PostgreSQL標準建表語句

2021-09-25 19:19:07 字數 1708 閱讀 6497

-- 建表

create table if not exists public.user

( id character varying(32) not null default sys_guid(),

name character varying(100) not null,

gender character varying(50) not null,

age character varying(10) not null,

id_no character varying(50) not null,

created_date timestamp without time zone default now(),

created_by character varying(100) default 'system',

updated_date timestamp without time zone default now(),

update_by character varying(100) default 'system',

constraint user_pkey primary key (id)

)with (oids = false);

-- 注釋

comment on table public.user is '使用者表';

comment on column public.user.id is '主鍵';

comment on column public.user.name is '姓名';

comment on column public.user.gender is '性別';

comment on column public.user.age is '年齡';

comment on column public.user.id_no is '身份證號';

comment on column public.user.created_date is '建立時間';

comment on column public.user.created_by is '建立人';

comment on column public.user.updated_date is '更新時間';

comment on column public.user.update_by is '更新人';

-- 主鍵 (如果建表語句裡面沒新增主鍵就執行該語句)

alter table public.user

add constraint user_pkey primary key (id);

-- 索引或唯一索引

drop index if exists user_name;

create index user_name on user (name);

drop index if exists user_id_no;

create unique index user_id_no on user (id_no);

-- 授權

grant all on table public.user to mydata;

grant select, update, insert, delete on table public.user to mydata_dml;

grant select on table public.user to mydata_qry;

Oracle標準建表語句

create table 建表 create table outln.customer id varchar2 32 default sys guid not null,cust id varchar2 64 cust name varchar2 255 id no varchar2 64 mobi...

MySQL最標準建表語句

sql分類 ddl 資料定義語言 dml 資料操縱語言 dcl 資料控制語言 create table t wxuser trade log id int 11 not null auto increment comment 序號 order id bigint 20 not null commen...

mysql建表語句

在sql語句中注意 約束的概念 1.實體完整性約束 主鍵 唯一且非空 primary key 違約處理 no action 拒絕執行 2.參照完整性約束 外來鍵約束 foregin key references tablename filedname on delete update casecad...