a表
sno xm
0001 王平
0002 余家
0003 审视 a1表
sno name
0001 陈伟
0002 王庭
0003 网闪闪
创建一个删除触发器 删除a表中的sno就能把a1表中相同的学号删除 以下语句有什么问题
create trigger a_table5 on a
after delete
as
begin
delete from a1 where sno in(select sno from deleted )
endgodelete from a where sno='0003'如果写删除和插入怎么写啊 !!
sno xm
0001 王平
0002 余家
0003 审视 a1表
sno name
0001 陈伟
0002 王庭
0003 网闪闪
创建一个删除触发器 删除a表中的sno就能把a1表中相同的学号删除 以下语句有什么问题
create trigger a_table5 on a
after delete
as
begin
delete from a1 where sno in(select sno from deleted )
endgodelete from a where sno='0003'如果写删除和插入怎么写啊 !!
=========================================--两张表数据同步 (添加、删除、修改 触发器) --建立环境create table table1 (sno varchar(10),sname varchar(10))
create table table2 (sno varchar(10),sname varchar(10))gocreate trigger t_table1 on table1
after delete,insert,update
as
begin
delete from table2 where sno in (select sno from deleted) if not exists (select 1 from table2 a,inserted i where a.sno=i.sno)
insert into table2
select * from inserted
else
update a set a.sname=i.sname from table2 a,inserted i where a.sno=i.sno
endgo
/**********插入记录************/insert into table1
select '0001','aa' union all
select '0002','bb' union all
select '0004','dd' select * from table1
select * from table2
--table1
/*
sno sname
----- -------
0001 aa
0002 bb
0004 dd
--table2
sno sname
------ -------
0001 aa
0002 bb
0004 dd
*/
/********删除记录*************/
delete from table1 where sno='0004'select * from table1
select * from table2--table1
/*
sno sname
----- -------
0001 aa
0002 bb--table2
sno sname
------ -------
0001 aa
0002 bb
*//***********更新记录************/
update table1 set sname='cc' where sno='0002'select * from table1
select * from table2--table1
/*
sno sname
----- -------
0001 aa
0002 cc--table2
sno sname
------ -------
0001 aa
0002 cc
*/
/********删除测试**********/drop table table1,table2
服务器: 消息 217,级别 16,状态 1,过程 a_table4,行 9
超出了存储过程、函数、触发器或视图的最大嵌套层数(最大层数为 32)。