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 -
ALTER TABLE {table_name} DROP CONSTRAINT {constraint_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?