从一个表中选择数据,然后插入到另一个表中
问题描述:
我有两个表SQL数据库,一个用户表和一个user_events表.单击按钮时,我需要从用户表中检索用户ID并插入到user_events表中的列中. .如果有人建议我替代此方法,我将不胜感激.
Hi,
I have two tables the SQL database, a user table and the user_events table .On button click i need to retrieve userid from user table and insert into a column in the user_events table.Can anyone tell me how to achieve the task on asp button click. I would be thankful if anybody suggest me an alternative for this.
答
尝试一下:
Try this :
INSERT INTO UserEvents(UserId)
SELECT UserId
FROM User
WHERE UserName='XXX'
看看: ^ ]
这可能对您有帮助
Have a look at :http://blog.sqlauthority.com/2007/08/15/sql-server-insert-data-from-one-table-to-another-table-insert-into-select-select-into-table/[^]
this might help you
这可能是实现此目的的一种方法:
This could be one way to do this:
SELECT *
INTO Persons_Backup
FROM Persons