Oracle自增长序号创建

--创建student表
create table STUDENT
(
  ID NUMBER not null,
  NAME VARCHAR2(20) default '男',
  SEX VARCHAR2(4),
  ADDRESS VARCHAR2(40),
  PHONE VARCHAR2(60)
)

--创建序列号
create sequence STU
minvalue 1
maxvalue 999999999999
start with 1 --开始值为1,增长1值
increment by 1
cache 20;

--创建触发器
create or replace trigger stu_tr---触发器
before insert on student 
for each row
declare
begin
select stu.nextval into :new.id from dual;
end stu_tr;



--删除序列号
drop sequence STU
select * from student;

猜你喜欢

转载自blog.csdn.net/magaiou/article/details/80322244