日期:2014-05-18  浏览次数:20415 次

高手: Sql 语句插入数据
insert into tab_name1 (uId,uEmail,typeName) 
select top 3 uId , kkEmail,kkTypeName from Tab_other

我想执行的同时做插入到另一个表
insert into tab_name2 (uId2,uEmail2,typeName2)

======
即我本来想 类似做这样的操作.

insert into tab_name1 (uId,uEmail,typeName) 
insert into tab_name2 (uId2,uEmail2,typeName2)
select top 3 uId , kkEmail,kkTypeName from Tab_other

请问怎么执行呢?

------解决方案--------------------
探讨
在tab_name1 上建立触发器

create trigger t1
on tab_name1
for insert
as
begin
insert into Tab_other
select uId,uEmail
from inserted
end

------解决方案--------------------
用output就行了


SQL code
insert into tab_name1 (uId,uEmail,typeName) 
OUTPUT INSERTED.uId,INSERTED.uEmail,INSERTED.typeName
INTO tab_name2
select top 3 uId , kkEmail,kkTypeName from Tab_other