Home:ALL Converter>drop all constraints in a postgresql table - drop cascade

drop all constraints in a postgresql table - drop cascade

Ask Time:2021-07-16T18:12:08         Author:The Great

Json Formatter

I have 21 tables in my database. However, there are some issues with the table schema (as we are trying to improve our data model). I already referred this post but it is for SQL server.

Currently, just for validation purpose, I would like to upload data inside them.

However, some ill-defined constraints are causing trouble.

So, I would like to delete all constraints only (from all tables) like Foreign key, check , unique, PK, Index etc.

How can I do this?

Currently I tried the below

ALTER TABLE subject
  DROP CONSTRAINT subject_details_pk CASCADE;
ALTER TABLE subject
  DROP CONSTRAINT subject_foreign_fk CASCADE;

As you can see, I have to write line by line across different tables (and manually find out which table is parent and which table is child etc).

So, is there any other way to drop all constraints in a table? Like Drop cascade ?

Can help me with this?

Author:The Great,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/68407270/drop-all-constraints-in-a-postgresql-table-drop-cascade
yy