PG DDL 常用语法
增加字段
alter table test add column_name int;
alter table task add testname varchar(32) not null;
修改字段名称
alter table test rename column status to status1;
修改字段类型,隐式转换
alter table task alter column cusid type varchar(32) ;
修改字段类型,显式转换
alter table task alter column customerid type int using customerid::int;
删除字段
alter table task drop column testid;
去除 not null
alter table task alter column remark drop not null;
设置 not null
alter table test alter column remark set not null;
设置默认值
alter table cus alter column xzqh set default 0;
创建表
create table test
(
id integer not null
constraint test_pkey
primary key,
testid integer not null,
tasktype smallint not null,
status smallint not null,
remark varchar(500) not null,
createtime timestamp not null
);
comment on table task is '任务';
comment on column test.tasktype is '注释';
alter table test owner to usertest;
postgresql | suger 2019-06-22 10:23:45