oracle 創建遞增觸發器
sql代碼
--1.創建表
create table tb_users
(
id number(4),
userName varchar2(20),
password varchar2(20)
)
--2.創建序列
create sequence sq_user
start with 1
increment by 1
--3.創建觸發器
create or replace trigger tri_tb_users
before insert on tb_users
for each row
begin
select sq_user.nextval into :new.id from dual;
end ;
--4.添加數據
begin
insert into tb_users(username,password) values('xiachufeng','xiachufeng');
insert into tb_users(username,password) values('Kevin','Kevin');
commit;
end;
--5.查詢數據 發現id列是遞增的
select * from tb_users
--1.創建表
create table tb_users
(
id number(4),
userName varchar2(20),
password varchar2(20)
)
--2.創建序列
create sequence sq_user
start with 1
increment by 1
--3.創建觸發器
create or replace trigger tri_tb_users
before insert on tb_users
for each row
begin
select sq_user.nextval into :new.id from dual;
end ;
--4.添加數據
begin
insert into tb_users(username,password) values('xiachufeng','xiachufeng');
insert into tb_users(username,password) values('Kevin','Kevin');
commit;
end;
--5.查詢數據 發現id列是遞增的
select * from tb_users