回答

收藏

尝试在PostgreSQL中修改约束

技术问答 技术问答 466 人阅读 | 0 人回复 | 2023-09-14

我检查了Oracle提供的文档找到了一种修改约束的方法,而无需删除表格。问题是修改时出错,因为无法识别关键字。% ]6 `$ [6 m. u' k' L
使用PostgreSQL的EMS SQL Manager。+ Y* m8 P  }  I/ V9 m
Alter table public.public_insurer_credit MODIFY CONSTRAINT public_insurer_credit_fk1    deferrable,initially deferred;我可以用以下方法删除约束来解决这个问题:
; w" U- f; H8 l: FALTER TABLE "public"."public_insurer_credit"  DROP CONSTRAINT "public_insurer_credit_fk1" RESTRICT;ALTER TABLE "public"."public_insurer_credit"  ADD CONSTRAINT "public_insurer_credit_fk1" FOREIGN KEY ("branch_id","order_id","public_insurer_id")    REFERENCES "public"."order_public_insurer"("branch_id","order_id","public_insurer_id")    ON UPDATE CASCADE    ON DELETE NO ACTION    DEFERRABLE     INITIALLY DEFERRED;                5 l" F+ w# J. b2 y  X
    解决方案:                                                               
" R" E, T0 @# ~  F4 c* Z. G! M  c/ l# _                                                                根据正确的手册(由PostgreSQL提供,而不    由Oracle提供),ALTER TABLE句子中没有可用的修改约束:
/ Y! j# y4 F, e# l6 Q  K5 a# Z这是正确手册的链接:' l3 m2 H4 L+ G8 r4 S; V9 b
http://www.postgresql.org/docs/current/static/sql-) s0 }8 u5 q+ \$ e) Z6 f
altertable.html
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则