oracle id 自动增长

--创建表

create table abc(
id number(4) not null primary key,
username varchar2(20) not null,
pwd varchar2(20) not null
);

--创建序列

create sequence abc_sequence
  increment by 1
  start with 1
  maxvalue 9999
  cycle nocache;

--创建触发器

create or replace trigger abc_trigger
       before insert on abc for each row
       begin
          select abc_sequence.nextval into:new.id from dual;
      end;

insert into abc(username, pwd) values(‘Tony‘, ‘a‘);

insert into abc(username, pwd) values(‘Tony1‘, ‘a‘);
select * from abc;

时间: 2024-08-30 01:18:36

oracle id 自动增长的相关文章

Oracle数据库自动增长列的实现过程

1.创建序列 -- Create sequence create sequence INNERID minvalue 1 maxvalue 99999999999999 start with 1 increment by 1 cache 20 order; 2.--INNERID.currval 指当前序列 --INNERID.nextval 指下一个序列 insert into admin values (INNERID.nextval,'a'); insert into admin valu

oracle设置id自动增长

1.创建增长序列 create sequence 序列名 minvalue 1 maxvalue 99999999999999999999 start with 1 increment by 1 nocache 2.创建触发器(关联表字段和序列) create or replace trigger 触发器名 before insert on 表名 for each row begin select 序列名.nextval into:new.表字段 from dual; end;

oracle设置自动增长序列

我们在用MS SQL Server时,可以为表的主键设置为自动加1的效果;但是在Oracle当中,我们是无法直接设置一个字段为自动加1,需要先建立一个Sequence,然后为这个表创建一个Trigger,具体步骤如下: 1.先建立一个Order表格,用如下SQL语句 create table SCOTT.ORDER(      ID          NUMBER(10) not null,      BUYER       CHAR(20) not null,      MERCHANDISE

sqlserver 2012 重启是 ID 自动增长 1000的问题

1. Open "SQL Server Configuration Manager"2. Click "SQL Server Services" on the left pane3. Right-click on your SQL Server instance name on the right pane ->Default: SQL Server(MSSQLSERVER)4. Click "Properties"5. Click &qu

创建触发器在表中播入数据时ID自动增长

create table ttt (id number primary key ,name varchar2(20),age number(2)) create or replace trigger gger_tt before insert on ttt for each row when (new.id is null) begin select ttt_sequence.nextval into :new.id from dual; end;

Powerdesigner16设置id自动增长

双击设置的table,然后双击Columns里面的primary key,然后,一次点击如下图标: 版权声明:本文为博主原创文章,未经博主允许不得转载.

oracle 数据表中实现字段的自动增长

由于一直用的是Mysql数据库,今天刚好心血来潮,想着和Java都是同一个老板出来的oracle自己却不会,说出去会不会有点丢人,故就开始翻资料,看视频搞起来,一步一个脚 印,想着写点什么,就开始从创建表开始吧,好了,废话不多说了,开始上正题创建一个表: User表: create table user(    id number(5,0) not null primary key auto_increment,    deptid number(5,0) not null,    userna

oracle添加数据时主键自动增长

CREATE TABLE STUDENT( --创建学生表  ID NUMBER(10) PRIMARY KEY,   --主键ID  SNAME VARCHAR2(20), ); 此时给学生表添加数据时 必须指定id INSERT INTO STUDENT VALUES(1,'Tom'); 下面用触发器和序列结合使得添加数据时id自动增长 不要指定了 --创建序列CREATE SEQUENCE SEQ_STUINCREMENT BY 1  ID每次自增几START WITH 1 ID从几开始自

oracle 主键应用序列和触发器实现自动增长

oracle 主键自动增长 这几天搞Oracle,想让表的主键实现自动增长,查网络实现如下: create table simon_example ( id number(4) not null primary key, name varchar2(25) ) -- 建立序列: -- Create sequence create sequence SIMON_SEQUENCE minvalue 1 maxvalue 999999999999999999999999999 start with 1