日期:2014-05-17 浏览次数:20441 次
create table OA_User(Uid int primary key ,uname varchar(20))
create table OA_tb
(
id int identity(1,1)primary key ,
Uid int foreign key references OA_User(Uid) on delete cascade --级联删除
)
insert into OA_User
values(1,'张三'),
(2,'李四')
insert into OA_tb
values(1),(1),(1),(2),(1)
--删除主表中udi 为2的记录,没有报错
delete from oa_user where uid = 2
--附表中的uid为2的记录,自动删除
select * from oa_tb
/*
id Uid
1 1
2 1
3 1
5 1
*/