Oracle数据库设置自增id
1.数据库配置:
‘DB_PREFIX’=>’tb_’,//表名前缀
‘DB_SEQUENCE_PREFIX’ => ‘seq_’,//序列名前缀
‘DB_TRIGGER_PREFIX’ => ‘tig_’,//触发器名前缀
2.先创建user数据表
表字段:id, username, password
3.然后创建[序列+触发器]
—-创建序列
create sequence seq_user
increment by 1
start with 1
nomaxvalue
nominvalue
nocache;
—-创建触发器
create or replace trigger “tig_user”
before insert on tb_user
for each row when(new.id is null)
begin
select seq_user.nextval into :new.id from dual;
end;
本文介绍了如何在Oracle数据库中设置自增ID,通过创建序列和触发器实现。首先,定义了数据库配置,包括表名、序列名和触发器名的前缀。接着,创建了一个名为'user'的数据表,包含'id'、'username'和'password'字段。然后,详细展示了创建序列'seq_user'的SQL语句,以及创建触发器'tig_user'的步骤,该触发器在插入新记录时自动为'id'字段分配序列值。
850

被折叠的 条评论
为什么被折叠?



