postgreSQL的主外鍵


--添加主鍵
alter table cities add PRIMARY KEY(name);
--添加外鍵
alter table weather add FOREIGN key(city) REFERENCES cities(name) on update CASCADE on DELETE CASCADE;
on update cascade: 被引用行更新時,引用行自動更新;
on update restrict: 被引用的行禁止更新;
on delete cascade: 被引用行刪除時,引用行也一起刪除;
on dellete restrict: 被引用的行禁止刪除;

--刪除外鍵
alter table orders drop constraint orders_goods_id_fkey;
--添加唯一約束
alter table goods add constraint unique_goods_sid unique(sid);
--刪除默認值
alter table goods  alter column sid drop default;
--修改字段的數據類型
alter table goods alter column sid type character varying;
--重命名字段
alter table goods rename column sid to ssid;









免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM