24号24秒

导航

 

外键:

查询:select object_name(a.parent_object_id) 'tables'  from sys.foreign_keys a  where a.referenced_object_id=object_id('B表')

格式(名称):FK_A表_B表

A表是主表,引用B表的id字段作为外键,删除B表时候,“无法截断表B,因为该表正由 FOREIGN KEY 约束引用。

删除外键:

alert table A表 drop constraint FK_A表_B表

清空表B

TRUNCATE TABLE B表

新增外键:

alert table A表 add constraint FK_A表_B表 foreign key (A表的id) references B表(B表的id)

posted on 2018-12-29 18:10  24号24秒  阅读(366)  评论(0编辑  收藏  举报