如何在SQL 2008中的另一个批量插入中进行批量插入 [英] How to do bulk insert within another bulk insert in SQL 2008

查看:85
本文介绍了如何在SQL 2008中的另一个批量插入中进行批量插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为testrun的表,其列有testrunid,name.testrunid是pk,自动增量。

另一个名为testrundetails的表,其中包含linkid,testrunid列.linkid是pk,自动增量。



现在每个testrun都有很多行应插入testrundetails。



现在插入查询本身通过创建数据表将数据批量插入到testrun中。

现在我的目标是使用testrun的每个插入行id来批量插入testrundetails(您可以从表结构中理解)。 />


所以我可以做一个插入,然后批量插入该插入查询的返回数据。但在这种情况下如何在批量插入中进行另一个批量插入。



我正在使用c#.net 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#.net 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中的另一个批量插入中进行批量插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆