问题描述
大家好,
我正在使用VS2008和sqlserver 2008
我有两个表user和user_events. users表具有自动递增的user_id.我想检索该user_id并将其插入到user_events表中.任何人都可以引导我进行此操作.在此先感谢
Hi all,
I am using VS2008 and sqlserver 2008
I have two tables users and user_events . users table has a auto increment user_id .I want to retrieve that user_id and insert into user_events table.can anyone guide me through this . thanks in advance
推荐答案
INSERT INTO Table2 (user_id)
VALUES (SELECT user_id from Table1 WHERE <condition> )
更多信息在这里
[ ^ ]
http://www.w3schools.com/sql/sql_select_into.asp [ ^ ]
http://stackoverflow.com/questions/4823880/sql-server-select-into-variable [ ^ ]
More info here
http://blog.sqlauthority.com/2007/08/15/sql-server-insert-data-from-one-table-to-another-table-insert-into-select-select-into-table/[^]
http://www.w3schools.com/sql/sql_select_into.asp[^]
http://stackoverflow.com/questions/4823880/sql-server-select-into-variable[^]
这篇关于将一个表中的自动递增列添加到另一表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!