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