ORACLE建立主鍵自增表

2021-05-23 05:24:08 字數 1418 閱讀 1923

--建立表,設定主鍵自增

create table stu(

uerid number(4) not null primary key,

username varchar(20),

userpass varchar(20),

email varchar2(30),

grade number(5)

);commit;

--小查一下

select * from stu;

--建立主鍵自增序列

create sequence emp_sequence

increment by 1

start with 1

nomaxvalue

nocycle

nocache;

commit;

--建立觸發器

create trigger "trigger_on_stu" before

insert on stu for each row when (new.uerid is null)

begin

select emp_sequence.nextval into :new.uerid from dual;

end;

--插入資料

insert into stu(username,userpass,email,grade) values('admin','admin','[email protected]',1);

insert into stu(username,userpass,email,grade) values('dhy','dhy','[email protected]',1);

insert into stu(username,userpass,email,grade) values('nsr','nsr','[email protected]',1);

insert into stu(username,userpass,email,grade) values('adamin','addmin','[email protected]',5);

insert into stu(username,userpass,email,grade) values('dhay','dhay','[email protected]',3);

insert into stu(username,userpass,email,grade) values('ansr','ansr','[email protected]',4);

commit;

--檢視資料

select * from stu;

如何建立主鍵自增表 oracle

建立表 create table t student id number 10 not null,createtime date not null,constraint pk t student primary key id 新增注釋 comment on table t student is 學生...

Oracle建立表 包含 主鍵自增

注意 oracle匯出建表語句不會匯出觸發器及自增索引 第一步 建立一張表 create table member memberid number primary key,主鍵 自增長 membermail varchar2 20 not null membername varchar2 20 no...

Oracle建立自增主鍵

create table scott student test sno number visible not null sname varchar2 255 byte visible varchar2 255 byte visible born varchar2 255 byte visible g...