If foreign key exists, drop it
-
27-04-2021 - |
Question
I have a table that has a foreign key relation with another table.
I want to check that if this relation exists, drop it.
How to I write this query.
Thanks.
Solution
If you are using SQL Server, this should works
if exists (select 1 from sys.objects where object_id = OBJECT_ID(N'[FKName]') AND parent_object_id = OBJECT_ID('TableName'))
alter table TableName drop constraint FKName
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow