CREATE TRIGGER tg_test ON A AFTER INSERT AS BEGIN SET NOCOUNT ON; declare @user varchar(10) declare @password varchar(10) select @user=[user],@password=[password] from inserted insert into C([user],[password]) select [user],[password] from B where [user]=@user and [password]=passwordEND
最后个password改为@password,漏写了- - 大致这样
create trigger t_name on A表 for insert as begin insert into c select a.* from B表 a,inserted b on a.id=b.id end
1楼的插入多行时会出错CREATE TRIGGER tg_test ON A AFTER INSERT AS insert into C select B.* from B join Inserted i ON B.ID=i.ID
CREATE TRIGGER tg_test
ON A
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON; declare @user varchar(10)
declare @password varchar(10) select @user=[user],@password=[password] from inserted insert into C([user],[password])
select [user],[password] from B where [user]=@user and [password]=passwordEND
大致这样
for insert
as
begin
insert into c
select a.* from B表 a,inserted b on a.id=b.id
end
ON A
AFTER INSERT
AS
insert into C
select B.* from B join Inserted i ON B.ID=i.ID