我Foreign keys一般如何掉线。我的意思是,如果我在表中有许多外键约束。喜欢
Foreign keys
MonthlyEvaluatedBudgetTable约束:
postgres中是否有办法删除所有外键,而不是专门删除现有表中的所有外键?我使用这行代码将外键删除到现有表中。
ALTER TABLE "public"."monthlyevaluatedbudgettable" DROP CONSTRAINT "accountid_fk";
但我想放弃它没有专门输入查询accountid_fk,branchid_fk,dept_fk。有办法吗?提前致谢。
accountid_fk
branchid_fk
dept_fk
在DO语句中循环,例如:
DO
b=# create table a (a int primary key, b int unique); CREATE TABLE b=# create table b (a int references a(a), b int references a(b)); CREATE TABLE b=# do $$ declare r record; begin for r in (select constraint_name from information_schema.table_constraints where table_schema = 'public' and table_name='b') loop raise info '%','dropping '||r.constraint_name; execute CONCAT('ALTER TABLE "public"."b" DROP CONSTRAINT '||r.constraint_name); end loop; end; $$ ; INFO: dropping b_a_fkey INFO: dropping b_b_fkey DO