加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql-server – 删除外键而不知道约束的名称?

发布时间:2020-12-12 16:42:58 所属栏目:MsSql教程 来源:网络整理
导读:我使用以下命令创建了一个表: create table Table1( Id int Not Null Foreign key references Table2(Id) on delete cascade on update cascade,UserName nvarchar(150),TimeInSeconds int Not Null primary key(Id,TimeInSeconds)); 但现在我想放掉外键. 因
我使用以下命令创建了一个表:
create table Table1(
    Id int Not Null 
        Foreign key 
        references Table2(Id)  
        on delete cascade 
        on update cascade,UserName nvarchar(150),TimeInSeconds int Not Null 

    primary key(Id,TimeInSeconds)
);

但现在我想放掉外键.
因为我没有给定约束名称我不能使用:

Alter table <tablename>
drop foreign key <foreign key name>

有什么办法吗请帮忙

解决方法

您可以在INFORMATION_SCHEMA.TABLE_CONSTRAINTS中找到约束的名称
select CONSTRAINT_NAME
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
where TABLE_NAME = 'Table1'

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读