添加外键,在T3,里面有id1,id2设置为主键,然后设置外键,
id1与T1中id1,外键关联,其中选择级联删除,on delete cascade
id2与T2中id2,外键关联,其中选择级联删除,on delete cascade
刚才在SQL2000中试了一下,可以实现
这个好办 你添加一个触发器
给T1添加删除触发器,当删除的时候,把T3中相关的数据删除
给T2同样操作
create trigger Tri_DeleteT1 on T1
for delete
as
begin
declare @id1 int
select @id1 = id1 from deleted
if exists (select * from id1 where id1 = @id1)
begin
delete from T3 where id1 = @id1
end
end
在sql server2000中如何设置主键 和外键? 1)主键 CREATE TABLE WL_Table_04 ( ID int PRIMARY KEY, Name char(8), Sex char(2) NOT NULL )