级联删除的注释:

发布网友 发布时间:2022-04-21 20:02

我来回答

1个回答

热心网友 时间:2023-07-08 10:42

是SQL吧?
alter table 表名

add constraint 外键名

foreign key(字段名) references 主表名(字段名)

on delete cascade

语法:

Foreign Key

(column[,...n])

references referenced_table_name[(ref_column[,...n])]

[on delete cascade]

[on update cascade]

注释:

column:列名

referenced_table_name:外键参考的主键表名称

ref_name:外键要参考的表的主键列

on delete:删除级联

on update:更新级联

表的外键约束

SELECT 外键表ID=b.fkeyid

,外键表名称=object_name(b.fkeyid)

,外键列ID=b.fkey

,外键列名=(SELECT name FROM syscolumns WHERE colid=b.fkey AND id=b.fkeyid)

,主键表ID=b.rkeyid

,主键表名=object_name(b.rkeyid)

,主键列ID=b.rkey

,主键列名=(SELECT name FROM syscolumns WHERE colid=b.rkey AND id=b.rkeyid)

FROM sysobjects a

join sysforeignkeys b on a.id=b.constid

join sysobjects c on a.parent_obj=c.id

where a.xtype='f' AND c.xtype='U'

查询一个表的所有外键:

SELECT 主键列ID=b.rkey

,主键列名=(SELECT name FROM syscolumns WHERE colid=b.rkey AND id=b.rkeyid)

,外键表ID=b.fkeyid

,外键表名称=object_name(b.fkeyid)

,外键列ID=b.fkey

,外键列名=(SELECT name FROM syscolumns WHERE colid=b.fkey AND id=b.fkeyid)

FROM sysobjects a

join sysforeignkeys b on a.id=b.constid

join sysobjects c on a.parent_obj=c.id

where a.xtype='f' AND c.xtype='U'

and object_name(b.rkeyid)='要查询的表名'

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com