How can I drop Foreign keys
in general. I mean, if I have many foreign key constraints in a table. like
MonthlyEvaluatedBudgetTable Contraints:
- budgetid_pk (Primary Key)
- branchid_fk (Foreign Key)
- accountid_fk (Foreign Key)
- dept_fk (Foreign Key)
Is there a way in postgres to drop all foreign keys in general and not specifically in an existing table? Im using this line of code to drop a foreign key in an existing table.
ALTER TABLE "public"."monthlyevaluatedbudgettable"
DROP CONSTRAINT "accountid_fk";
But I want to drop It without specifically inputing accountid_fk
,branchid_fk
,dept_fk
. Is there a way on it? thanks in advance.
Thank you Vao Tsun for the solution. It helped me.
In my case (Posgresql 9.6) I just had to add a minor "improvement"
and constraint_name like 'fk_%'
additional constraint to prevent errors like:Loop it in
DO
statement, like: