表上的级联插入

来源:互联网 发布:二手已备案域名 编辑:程序博客网 时间:2024/06/06 04:22

create trigger tduStudent
on aa for insert
as
begin
declare @id int
select @id=id from inserted
insert into bb (id) values(@id)
end


drop table aa
create table aa  (
   id                   int       identity(1,1)                   not null,
   name                 VARCHAR(10),
   sex                  int,
   constraint PK_AA primary key (id)
);

insert into aa values('123',1);

drop table bb
create table bb  (
   id                   int                          not null,
   name                 VARCHAR(20),
   ffff                 VARCHAR(20),
   constraint PK_BB primary key (id)
);

update bb set name='123', ffff='123' where id in (SELECT MAX(id) FROM bb);

select * from bb
alter table bb
   add constraint FK_BB_REFERENCE_AA foreign key (id)
      references aa (id) ON DELETE CASCADE;

原创粉丝点击