07-31-2023, 09:19 AM
If you are looking for other type of constraint, e.g. defaults, you should use different query
(From
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"][2]
[1]:
(From
[To see links please register here]
answered by [devio][1]). 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"][2]
[1]:
[To see links please register here]
[2]:[To see links please register here]