Set primary key id auto increase in Oracle

作者: shaneZhang 分类: 数据库 发布时间: 2019-09-29 20:58
 // create sequence
 create sequence LOG_MAIN_SEG
 increment by 1
 start with 1
 minvalue 1
 maxvalue 999999999;

 // get autoincrease value
 select  LOG_MAIN_SEG.Nextval ID from dual;
Below is the learning content:

--创建示例表 --
create table Student(
    stuId number(9) not null,
    stuName varchar2(20) not null,
    stuMsg varchar2(50) null
)
  
  -- 创建序列  Student_stuId_Seq --
 create sequence Student_stuId_Seq
 increment by 1
 start with 1
 minvalue 1
 maxvalue 999999999;
 
 -- 更改序列  Student_stuId_Seq--
 alter sequence Student_stuId_Seq
    increment by 2  
    minvalue 1
    maxvalue 999999999;
 
 --获取序列自增ID --
 select Student_stuId_Seq.Nextval 自增序列ID from dual;
 
 -- 删除序列 -- 
 drop sequence Student_stuId_Seq;
 
 --调用序列,插入Student数据 --
 insert into Student(stuId,Stuname) values(Student_stuId_Seq.Nextval,'张三');
 insert into Student(stuId,Stuname) values(Student_stuId_Seq.Nextval,'李四');
 --查询插入的数据 --
 select * from Student

本页面支持繁体中文友好显示:Set primary key id auto increase in Oracle

如果觉得我的文章对您有用,请随意打赏。如果有其他问题请联系博主QQ(909491009)或者下方留言!

发表回复