postgres 8.0+ alter语句系列

来源:互联网 发布:学校机房网络一般布局 编辑:程序博客网 时间:2024/05/17 08:57

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;


原创粉丝点击