postgres 8.0+ alter語句系列

1. 添加唯一性約束

alter table table_name add constraint constraint_name unique(column_name);

2.添加外建約束

alter table table_name add constraint constraint_name FOREIGN KEY (table_name_id) REFERENCES table_foreign(id)

smaple:

alter table deploys add constraint deploys_users_id FOREIGN KEY (user_id) REFERENCES users(id);

3.添加/去除 不可爲空屬性

alter table table_name alter column column_name set/drop not null;

4.更改類型

alter table table_name alter column column_name type type_name;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章