db2 資料庫主鍵自增
阿新 • • 發佈:2018-11-23
DBeaver中,主鍵自增無法勾選,可通過建表語句實現自增。
在自增的column後新增如下語句
GENERATED ALWAYS AS IDENTITY ( START WITH +1 INCREMENT BY +1 MINVALUE +1 MAXVALUE +2147483647 NO CYCLE CACHE 20 NO ORDER )
其中:
NO CYCLE:到達最大值後,不迴圈回來
CACHE:快取20個值,提高效能
NO ORDER:指定identity值不必按照請求順序生成
完整建表語句,如下:
CREATE TABLE ADMINISTRATOR.DAT_LOG ( LOD_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY ( START WITH +1 INCREMENT BY +1 MINVALUE +1 MAXVALUE +2147483647 NO CYCLE CACHE 20 NO ORDER ), LOD_TIME TIMESTAMP DEFAULT NULL, LOG_USERID varchar(50) DEFAULT NULL, LOG_USERNAME varchar(50) DEFAULT NULL, LOG_DESC varchar(3000) DEFAULT NULL, PRIMARY KEY (LOG_ID) )