读书人

sql 触发器. 急 呀. 分不够在家啊

发布时间: 2012-01-28 22:06:13 作者: rapoo

sql 触发器.. 急急, 在线等呀. 分不够在家啊.
比如;
tb1
id nana
1 a
2 b
3 c

tb2
id nana
1 a
2 b

当表tb1 或 tb2 每添加一条记录时,触发

添加到表
tb3
id name type
1 a tb1
2 b tb1
3 c tb1
1 a tb2
2 b tb2

帮我写个这样的触发器.谢了

[解决办法]
create trigger ti_tb1 on tb1
for insert
as
insert into tb3(id,name,type)
select id,nana, 'tb1 ' from inserted
go
create trigger ti_tb2 on tb2
for insert
as
insert into tb3(id,name,type)
select id,nana, 'tb2 ' from inserted
[解决办法]
CREATE TRIGGER tritest
ON tb1 --在表tb1上建触发器tritest
for INSERT --插入时
AS --主体部分
insert into tb3 inserted.id,insertd.name, 'tb1 ' --插入的id及name插到tb3中,并将 'tb1 '插入type中
go
CREATE TRIGGER tritest1
ON tb2
for INSERT
AS
insert into tb3 inserted.id,insertd.name, 'tb2 '

读书人网 >SQL Server

热点推荐