oracle中如何设置主键并且让其自动增长
1、创建数据库
create table USERINFO
(
USERNO NUMBER not null,
USERNAME NVARCHAR2(20),
USERPWD NVARCHAR2(20)
)
2、创建触发器
create sequence SEQ_Userinf start with 1 increment by 1
nomaxvalue
nominvalue
nocache;
CREATE OR REPLACE TRIGGER tg_test
BEFORE INSERT ON Userinfo
FOR EACH ROW WHEN (new.userNo is null)
begin
select SEQ_Userinf.nextval into:new.userNO from dual;
end;
3、测试,插入数据
insert into USERINFO(USERNAME,USERPWD) values('范围广','322');