如何在Sql Server 2005中实现批量插入功能
我在数据库中有一个名为 user 的表,其中包含以下条目。
Userid FirstName LastName
1 fa la
2 fb lb
3 fc lc
和另一个表用户表单
Userformid Userid Form Code modifieddate Isclosed IsForm
1 1 ff cc somedate 0 0
2 1 gg rr somedate 0 0
3 1 bb bb somedate 0 0
4 2 ss aa somedate 0 0
5 2 qq sa somedate 0 0
6 3 ws xc somedate 0 0
现在我必须为用户表单表中的每个用户ID插入新记录,并且只有表单和代码列应该仅按最新修改日期从用户表单表复制到插入行中(类似于:-按修改日期描述排序。)
Output should be in userform table :
Userformid Userid Form Code modifieddate Isclosed IsForm
1 1 ff cc somedate 0 0
2 1 gg rr somedate 0 0
3 1 bb bb somedate 0 0
4 2 ss aa somedate 0 0
5 2 qq sa somedate 0 0
6 3 ws xc somedate 0 0
newly added row
7 1 bb bb newdate 0 0
8 2 qq sa newdate 0 0
9 3 ws xc newdate 0 0
有6000个记录在用户表和用户表单表中。
我们如何使用批量插入功能或使用 sql server 2005 中的任何其他技术来实现这一点。我不想使用游标。
I have a table in database called user which has following entries.
Userid FirstName LastName
1 fa la
2 fb lb
3 fc lc
and another table userform
Userformid Userid Form Code modifieddate Isclosed IsForm
1 1 ff cc somedate 0 0
2 1 gg rr somedate 0 0
3 1 bb bb somedate 0 0
4 2 ss aa somedate 0 0
5 2 qq sa somedate 0 0
6 3 ws xc somedate 0 0
Now i have to insert new record for every userid in userform table and only Form and Code column should get copied in inserted row from userform table only by latest modifieddate ( something like:- order by modifieddate desc.)
Output should be in userform table :
Userformid Userid Form Code modifieddate Isclosed IsForm
1 1 ff cc somedate 0 0
2 1 gg rr somedate 0 0
3 1 bb bb somedate 0 0
4 2 ss aa somedate 0 0
5 2 qq sa somedate 0 0
6 3 ws xc somedate 0 0
newly added row
7 1 bb bb newdate 0 0
8 2 qq sa newdate 0 0
9 3 ws xc newdate 0 0
There are 6000 record in user table and userform table.
How can we achieve this using bulk insert feature OR using any other technics in sql server 2005.I don't want to use CURSOR.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样,使用 ROW_NUMBER 应该可以解决问题。首先尝试不使用 INSERT 来检查它返回的结果。如果这就是您想要的,只需取消注释 INSERT 行并继续。
Something like this, making use of ROW_NUMBER should do the trick. Try it first without the INSERT to check the results it returns. If that is then what you want, just uncomment the INSERT line and go ahead.