200 ? "200px" : this.width)!important;}
-->

介绍

本篇文章主要介绍在oracle中如果创建自增长表,这里要用到序列。

create table tb_student
(
id NUMBER(10) not null,
createtime DATE not null,
constraint PK_tb_student primary key (id)
); comment on table "tb_student" is
'学生表'; comment on column "tb_student"."id" is
'主键id'; comment on column "tb_student"."createtime" is
'创建时间'; --创建序列
create sequence seq_tb_student
minvalue 1
nomaxvalue
start with 1
increment by 1
nocycle --一直累加,不循环
--nocache; --不缓存
cache 10; --缓存10条 --创建触发器,如果insert语句不指定ID自动插入增长值
CREATE OR REPLACE TRIGGER tr_tb_student
BEFORE INSERT ON tb_student FOR EACH ROW WHEN (new.id is null)
begin
select seq_tb_student.nextval into:new.id from dual;
end;

注意:触发器是非必须的,可以从业务上严格要求指定插入值。

总结

注意oracle限制对象名的字符长度不能超过30个字符,所以表名要控制在一定的长度否则后面创建序列可能会超过限制,建议表名控制在27个字符以下。

备注:

作者:pursuer.chen

博客:http://www.cnblogs.com/chenmh

本站点所有随笔都是原创,欢迎大家转载;但转载时必须注明文章来源,且在文章开头明显处给明链接。

《欢迎交流讨论》

Oracle 创建主键自增表的更多相关文章

  1. Oracle创建主键自增表

    Oracle创建主键自增表   1.创建表    create table Test_Increase(            userid number(10) NOT NULL primary k ...

  2. springboot集成jpa,在postgresql数据库中创建主键自增表

    依赖文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http:/ ...

  3. Oracle创建主键优劣

    创建主键方式 一个表的主键是唯一标识,不能有重复,不允许为空. 一个表的主键可以由一个字段或多个字段共同组成. -- 列级,表级建立主键 1.create table constraint_test ...

  4. MySQL,Oracle建立主键自增表

    MySQL 在建表的时候声明字段即可 id int auto_increment primary key not null Oracle 第一步:建立表 drop table t_role; crea ...

  5. 笔记 oracle 创建主键自增长

    笔记 (1) 创建表 create table test( id number(18,2) primary key, -- 主键(unique+not null) name varchar2(100) ...

  6. oracle创建主键序列和在ibatis中应用

    oracle创建主键序列 oracle主键序列的查询和ibitas中应用

  7. 5.oracle建表的时候同时创建主键,外键,注释,约束,索引

    5.oracle建表的时候同时创建主键,外键,注释,约束,索引 1 --主键 )); ) ,constraint aba_pr primary key(id,name1)); --外键 )); --复 ...

  8. oracle建表的时候同时创建主键,外键,注释,约束,索引

    --主键create table emp (id number constraint id_pr primary key ,name1 varchar(8));create table emp9 (i ...

  9. oracle快速创建主键

    oracle中,有时我们会发现有一些表中,一些记录它们每个字段的数据 都是一样一样的,即重复数据,这种数据的不存在肯定是不对了. 究其原因,就是该表没有主键,给一个表创建主键,非常容易: alter ...

随机推荐

  1. HDOJ(1242)BFS+优先队列

    Rescue http://acm.hdu.edu.cn/showproblem.php?pid=1242 题意:"#"是墙,"."是路,"a&quo ...

  2. html a tag's href javascript issue

    a标签的href中写js中遇到的问题(ie中有问题,chrome没问题) <a class="free" href="javascript:{$('#suiteTy ...

  3. Linux_04------Linux权限的设定

    三种权限 */ /** * 修改文件所有者 * chown 用户名 文件名 */

  4. css 透明(transparent)

    opacity :  .75;     //standard css3 style for transparency -moz-opacity : .75;        // transparenc ...

  5. 泛型的上限和下限的Demo

    Main Class package Comparator.Bean; import java.math.BigDecimal; import java.util.List; import java. ...

  6. Get the Uniqueid of Action Originate in the AMI

    [asterisk-users] Get the Uniqueid of Action Originate in the AMI Adolphe Cher-Aime acheraime at gmai ...

  7. Extjs学习笔记--Ext.tree.Panel

    Ext.create('Ext.tree.Panel', { title: 'Simple Tree', width: 200, height: 150, store: store, rootVisi ...

  8. Raspberry Pi(树莓派)国内软件源

    树莓派自带的软件源是 deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi 由于网站在国外 ...

  9. swift 如何获取webView的内容高度

    应用中如果使用webView,要想获取其内容高度,就要实现其代理方法, 首先添加代理UIWebViewDelegate 然后给代理赋值 webView.delegate = self 实现代理方法: ...

  10. node.js 基础学习笔记3 -http

    http模块,其中封装了一个高效的HTTP服务器和一个建议的HTTP客户端 http.server是一个基于事件的HTTP服务器 http.request则是一个HTTP客户端工具,用户向服务器发送请 ...