oracle创建自增长列

时间:2023-03-09 23:26:14
oracle创建自增长列

--创建一个新表

/*create table students(
stu_id number,
stu_name varchar2(20),
stu_email varchar2(40),
primary key(stu_id));*/
--新建一个自增长序列
/*CREATE SEQUENCE SEQ_students

minvalue 1

maxvalue 99999999

start with 1

increment by 1

nocache order;*/
--新建触发器
/*CREATE OR REPLACE TRIGGER AUTOINCREMENT
BEFORE INSERT ON students
FOR EACH ROW
WHEN (NEW.STU_ID IS NULL)
BEGIN
SELECT SEQ_students.NEXTVAL INTO :NEW.STU_ID FROM DUAL;
END;*/

/*INSERT INTO STUDENTS(STU_NAME) VALUES('fonnyfu');*/