如何在SQL 2008中的另一个批量插入中进行批量插入

编程入门 行业动态 更新时间:2024-10-14 14:14:26
本文介绍了如何在SQL 2008中的另一个批量插入中进行批量插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个名为testrun的表,其列有testrunid,name.testrunid是pk,自动增量。 另一个名为testrundetails的表,其中包含linkid,testrunid列.linkid是pk,自动增量。 现在每个testrun都有很多行应插入testrundetails。 现在插入查询本身通过创建数据表将数据批量插入到testrun中。 现在我的目标是使用testrun的每个插入行id来批量插入testrundetails(您可以从表结构中理解)。 /> 所以我可以做一个插入,然后批量插入该插入查询的返回数据。但在这种情况下如何在批量插入中进行另一个批量插入。 我正在使用c# 4.0。 我尝试了什么: 您可以发布任何流程,我会吸收它。

I have a table named "testrun" having columns "testrunid,name".testrunid is pk,auto increment. Another table named "testrundetails" having column "linkid,testrunid".linkid is pk,auto increment. Now for each testrun there are many rows should be inserted into testrundetails. Now an insert query itself bulk inserting data into testrun by making datatable. Now my goal is to bulk insert into testrundetails with each inserted row id of testrun (you can understand from table structure). So I can do one insert and then bulk insert with returned data of that insert query. But in this case how to do another bulk insert within a bulk insert. I'm using c# 4.0. What I have tried: You can post any process,I'll absorb that.

推荐答案

恕我直言,我会把它分成更小的块。 0)插入一个新的testrun项目,并得到从最近插入的项目的数据库中得到的id。 1)使用返回的testrun id对详细项目进行批量插入。 这样会更容易调试。 由于代码是您的用户ID的一部分,我将离开编码在你明显有能力的人手中。 IMHO, I would break it into smaller chunks. 0) Insert a new testrun item, and get the resulting id from the database for the recently inserted item. 1) Do a bulk insert on detail items with that returned testrun id. That would be easier to debug. Since "code" is part of your user ID, I'll leave the act of "coding" in your obviously capable hands.

INSERT INTO testrun(testrunid,name) SELECT linkid,testrunid FROM testrundetails

检查它是否有效!!!

Check it would work!!!

更多推荐

如何在SQL 2008中的另一个批量插入中进行批量插入

本文发布于:2023-10-27 10:34:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533111.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:批量   如何在   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!