postgresql 创建表


1、创建表

CREATE table tb_user
(
    id serial primary key not null ,
    name varchar(20) not null default '' 
) ;


comment on column tb_user.id is '主键id';

comment on column tb_user.name is '用户名';

comment on table tb_user is '用户表';

-- 设置主键自增  serial

-- 设置表的备注信息

comment on table 表名 is '表注释';
comment on table tb_user is '用户表';

-- 设置列名备注

comment on column 表名.字段名 is '字段注释';
comment on column tb_user.name is '用户名';

-- 修改表名

alter table 原表名 rename to 新表名;
-- 关键字目前测试是不能当表名 alter table tb_user rename to user1;

-- 修改列名

alter table 表名 rename 字段名 to 新字段名
-- 还没经过测试

 -- 设置索引

create index 索引名称 on 表名 (列名);
create index idx_create_user on leave (create_user);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM