【oracle】创建自增主键
2016-06-07 09:34
375 查看
1. 创建表
--创建 表 temp
create table temp (
id number primary key not null,
time date default sysdate
)
2. 创建序列
create sequence temp_seq
start with 1 --从1开始
increment by 1 --每次自增1
nomaxvalue --没有最大值
nocycle --不循环
nocache --不缓存
3.创建触发器
create or replace trigger temp_trigger
before
insert on temp for each row when (new.id is null) --执行条件
begin
select temp_seq.nextval into :new.id from dual; --执行语句
end;
--创建 表 temp
create table temp (
id number primary key not null,
time date default sysdate
)
2. 创建序列
create sequence temp_seq
start with 1 --从1开始
increment by 1 --每次自增1
nomaxvalue --没有最大值
nocycle --不循环
nocache --不缓存
3.创建触发器
create or replace trigger temp_trigger
before
insert on temp for each row when (new.id is null) --执行条件
begin
select temp_seq.nextval into :new.id from dual; --执行语句
end;
相关文章推荐
- cx_Oracle安装 评分卡完善 2016.06.06回顾
- Oracle密码过期问题
- oracle with as临时表用法 分组group by
- Oracle RMAN 的 show,list,crosscheck,delete命令整理
- Oracle ORA-01033: ORACLE initialization or shutdown in progress 错误解决办法
- oracle win7下 卸载
- oracle游标使用
- Oracle 表空间详解
- oracle lag与lead分析函数简介
- Oracle中Package与Package body的介绍
- Oracle函数-DECODE
- Oracle一列的多行数据拼成一行显示字符
- Oracle建立表空间和用户
- 深入理解Oracle数据库group by语句
- oracle_3 数据操作
- 2016.6.6
- 数据库优化 SQLServer mysql Oracle
- oracle imp/exp 备份使用
- oracle11g 一条几百行行的sql语句 优化 需要适可而止才行
- ORACLE 两个表或两个结果集的数据对比常用的函数