想删除外键,但如何判断该外键是否已经存在?谢谢
ALTER TABLE dbo.table1
DROP CONSTRAINT fk_foreignkey1
怎么再写个if exists来判断这个外键只在存在的情况下才删除?
谢谢!!
[解决办法]
if exists(select 1 from sysobjects where name= 'fk_foreignkey1 ' and xtype= 'F ')
ALTER TABLE dbo.table1 DROP CONSTRAINT fk_foreignkey1
[解决办法]
if exists (
select 1 from sysobjects
where name= 'fk_foreignkey1 '
and type= 'f '
)
ALTER TABLE dbo.table1
DROP CONSTRAINT fk_foreignkey1