PostgreSQL
1、增加一列
ALTER TABLE table_name ADD column_name datatype;
2、删除一列
ALTER TABLE table_name DROP column_name;
3、更改列的数据类型
ALTER TABLE table_name ALTER column_name TYPE datatype;
4、表的重命名
ALTER TABLE table_name RENAME TO new_name;
5、更改列的名字
ALTER TABLE table_name RENAME column_name to new_column_name;
6、字段的not null设置
ALTER TABLE table_name ALTER column_name {SET|DROP} NOT NULL;
7、给列添加default
ALTER TABLE table_name ALTER column_name SET DEFAULT expression;
comment on table xttblog is '业余草';
create table xttblog(id int not null, url_id int);
comment on column xttblog.id is '主键ID,自增';
===================================================================================
ALTER TABLE t_onlyou_form ADD picture_display VARCHAR(100);
ALTER TABLE t_onlyou_form ADD filling_instructions VARCHAR(300);
ALTER TABLE t_onlyou_form ALTER form_desc TYPE VARCHAR(300); --从128修改为300
COMMENT ON COLUMN t_onlyou_form.picture_display IS '图片展现';
COMMENT ON COLUMN t_onlyou_form.filling_instructions IS '填写说明';
ALTER TABLE t_onlyou_form DROP picture_display;
ALTER TABLE t_onlyou_form DROP filling_instructions;
COMMIT;