我有一个表,比方说table3
,它包含两个外键,每个外键引用一个不同的表。我想知道,我可以为它们定义两个不同的ON DELETE
动作。
让我通过一个例子解释一下。
create table table3 (
ID varchar(255),
Name varchar(255),
primary key(ID,Name),
foreign key(ID) References user(id),
foreign key(Name) References shops(StoreName)
on update cascade
on delete cascade // I want to cascade table if id is deleted
on delete no actions); // and do not allowed if StoreName is deleted.
有人帮我吗?提前谢谢。
答案 0 :(得分:0)
不确定我是否完全理解您要做的事情 - 但是如果您希望{f}引用ON DELETE CASCADE
表上的User
和fk上的ON DELETE NO ACTIONS
对Shops
表的引用,您需要使用此T-SQL:
create table table3 (
ID varchar(255),
Name varchar(255),
primary key(ID,Name),
foreign key(ID) References user(id)
on delete cascade, // I want to cascade table if id is deleted
foreign key(Name) References shops(StoreName)
on update cascade
on delete no actions); // and do not allowed if StoreName is deleted.
您需要使用ON DELETE ....
定义
foreign key
操作权限