Script to drop foreign keys in a table - PostgreSQL

How to drop foreign keys in a PostgreSQL database ?

Use the below query to list the all foreign keys in a table, execute the generated output query to drop the foreign keys in a table. If table name not specified, the query will return the foreign key details of that database. Use the output query to remove entire foreign keys in a database.

Script to drop foreign keys in a table - PostgreSQL

SELECT DISTINCT 'ALTER TABLE ' ||tc.table_name||' DROP CONSTRAINT'|| tc.constraint_name ||';'
FROM information_schema.table_constraints tc
JOIN information_schema.key_column_usage kcu
     ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage ccu
     ON ccu.constraint_name = tc.constraint_name
WHERE constraint_type = 'FOREIGN KEY'
     AND ccu.table_name='tablename' -- specify the table name

Please visit other related articles

PostgreSQL: Add macros in PgAdminIII
PostgreSQL: Export PostgreSQL data in to excel file
PostgreSQL: How to restrict the user access to the databases in Postgresql based on the permission
PostgreSQL: List table details using Alt+F1 in PostgreSQL