oracle 主键自增

2。建表:

create table position
(
 id number(10) not null,
 deviceName varchar2(30) not null primary key,
 imageName varchar2(30) not null,
 effectName varchar2(30) not null,
 xPos number(6) not null,
 yPos number(6) not null,
 data number(10,4)
)
tablespace users
/

 

3。建序列:

create sequence position_seq

start with 1

increment by 1

minvalue 1

maxvalue 9999999

nocycle

nocache

noorder;

/

4。建触发器:

create or replace trigger position_trigger
  before insert on position
  for each row
begin
    select position_seq.nextval into:new.id from sys.dual;
end;
/

你可能感兴趣的:(oracle)