How to check if a Constraint exists in Sql server?

前端 未结 13 2001
无人及你
无人及你 2020-11-29 15:03

I have this sql:

ALTER TABLE dbo.ChannelPlayerSkins
    DROP CONSTRAINT FK_ChannelPlayerSkins_Channels

but apparently, on some other databa

13条回答
  •  遥遥无期
    2020-11-29 15:44

    If you are looking for other type of constraint, e.g. defaults, you should use different query (From How do I find a default constraint using INFORMATION_SCHEMA? answered by devio). Use:

    SELECT * FROM sys.objects WHERE type = 'D' AND name = @name
    

    to find a default constraint by name.

    I've put together different 'IF not Exists" checks in my post "DDL 'IF not Exists" conditions to make SQL scripts re-runnable"

提交回复
热议问题