日期:2014-05-19  浏览次数:20793 次

想删除外键,但如何判断该外键是否已经存在?谢谢
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