PostgreSQL 建立主鍵自增表的 DDL

hapday發表於2024-10-07

PostgreSQL 建立主鍵自增表的 DDL

-- 社群表
DROP TABLE IF EXISTS public.t_community;

CREATE TABLE public.t_community (
    id bigserial NOT NULL,
    grid_id int8 NULL,
    name varchar(128) NOT NULL,
    description varchar(4096) NULL,
    create_time timestamp DEFAULT CURRENT_TIMESTAMP NULL,
    update_time timestamp NULL,
    remark varchar(4096) NULL,
    removed bool DEFAULT false NULL,
    version int4 DEFAULT 1 NULL,
    CONSTRAINT t_community_primary_key PRIMARY KEY (id)
);

COMMENT ON TABLE t_community IS '社群表';
COMMENT ON COLUMN t_community.id IS '唯一標識,透過序列自增。';
COMMENT ON COLUMN t_community.grid_id IS '網格的唯一標識';
COMMENT ON COLUMN t_community.name IS '名稱';
COMMENT ON COLUMN t_community.description IS '描述';
COMMENT ON COLUMN t_community.create_time IS '建立時間,一旦建立則不可再改變';
COMMENT ON COLUMN t_community.update_time IS '更新時間,只要有資料變動此值就會改變。';
COMMENT ON COLUMN t_community.remark IS '備註';
COMMENT ON COLUMN t_community.removed IS '是否已移除:假是未移除,真是已移除。';
COMMENT ON COLUMN t_community.version IS '版本號';

相關文章