Skip to content
Advertisement

DROP Constraint without knowing the name

I know there are a lot of references out there for what I am going to mention.

I am rather sharing something I feel should be very useful and consolidating in one place – Q&A-style. I have struggled earlier finding this for different constraints on different time.

The following constraints are commonly used:

  • Primary key Constraint
  • Foreign key Constraint
  • Unique Constraint
  • Not Null Constraint
  • Default Constraint
  • Check Constraint

It is pretty easy to DROP a constraint if you know the name –

But most of the times we use to define constraints at the time of creating tables and without name. Some time later, if we decide to drop any constraint, it is not that straightforward and we do need to write some comparatively complex queries.

So, how do we do this?

Advertisement

Answer

Some of the queries are from my local repository and some are taken references from different sources:

Finding a Primary Key Constraint on the fly in SQL Server 2005

Drop Foreign Key without knowing the name of the constraint?

How to drop a unique constraint from table column?

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement