[英]On delete actions when a table has a 2 foreign key from 2 different tables
我有一個表,比方說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.
有沒有人可以幫助我? 提前致謝。
不知道我是否完全了解您要做什么-但是如果您想在對User
表的fk引用上具有ON DELETE CASCADE
,在對Shops
表的fk引用上具有ON DELETE NO ACTIONS
,則需要使用此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.
您需要直接使用foreign key
定義指定ON DELETE ....
操作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.