【数据库】Oracle建表、创建序列、添加触发器生成自增主键

时间:2022-11-04 07:55:23
CREATE TABLE "TEST"."T_ORDER" (
"AUUID_0" VARCHAR2 ( 255 ) NOT NULL ENABLE,
"Order_ID" VARCHAR2 ( 255 ) NOT NULL ENABLE,
"User_ID" VARCHAR2 ( 255 ) NOT NULL ENABLE,
"CREATE_DATE" TIMESTAMP ( 2 ) DEFAULT SYSDATE,
"UPDDATTIM_0" TIMESTAMP ( 2 ) DEFAULT SYSDATE,
CHECK ( "AUUID_0" IS NOT NULL ) ENABLE,
CHECK ( "Order_ID" IS NOT NULL ) ENABLE,
CHECK ( "User_ID" IS NOT NULL ) ENABLE
) SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE ( INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT ) TABLESPACE "USERS";
CREATE
OR REPLACE TRIGGER "TEST"."Auto_Trig_T_Order_copy1" BEFORE INSERT ON "TEST"."T_ORDER" REFERENCING OLD AS "OLD" NEW AS "NEW" FOR EACH ROW

WHEN ( new."AUUID_0" IS NULL ) BEGIN
SELECT
test_seq_SORDERQ.nextval INTO : new."AUUID_0"
FROM
dual;

END;
ALTER TRIGGER "TEST"."Auto_Trig_T_Order_copy1" ENABLE

作者:​​哥们要飞​​