在不知道约束名称的情况下删除外键? [英] Drop Foreign Key without knowing the name of the constraint?

查看:30
本文介绍了在不知道约束名称的情况下删除外键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下命令创建了一张表:

I have created one table using below command:

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)
);

但现在我想删除外键.由于我没有给出我不能使用的约束名称:

But now I want to drop the foreign key. As i havent given constraint name I cant use:

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

有什么办法吗?请帮忙.

Is there any way? Pls help.

推荐答案

你可以在INFORMATION_SCHEMA.TABLE_CONSTRAINTS

select CONSTRAINT_NAME
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
where TABLE_NAME = 'Table1'

这篇关于在不知道约束名称的情况下删除外键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆