1

假设我有一个表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.

有没有人可以帮助我?提前致谢。

4

1 回答 1

0

不确定我是否完全理解您要执行的操作 - 但如果您希望对ON DELETE CASCADEUserON DELETE NO ACTIONSfk 引用和对表的 fk 引用有,则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

于 2013-11-10T09:58:45.720 回答