zoukankan      html  css  js  c++  java
  • Oracle中添加自动编号的序列

    1. 创建表T_Test
    create table T_Test(id int  ,address char(25), pay int);

    2. 创建自增序列
    create sequence SEQ_T_Test_ID    //创建名为zc的序列
      increment   by   1    //自增长度为1
      start   with   1     //从1开始计数
      minvalue 1     //最小值为1
      nomaxvalue    //没有最大值
      nocache;      //不设置缓存

    3. 为表T_Test创建触发器
    create or replace trigger T_Test_id  //将触发器绑定在 id 这一列
    before insert
    on T_Test
    for each row
    when(new.id is null)
    begin
    select SEQ_T_Test_ID.nextval into:new.id from dual;
    end;

    4. 插入数据
    insert into T_Test (address,pay) values('anh3u1i',345);
    或者
    insert into  T_Test  values(SEQ_T_Test_ID.nextval,'anh3u1i',345);
  • 相关阅读:
    5.18英语
    5.18
    5.17
    单源点最短路模板
    5.16
    mock.js进行接口mock
    docker-compose安装和使用
    docker常用命令
    docker安装和使用(win10家庭版)
    ES6基础(2)-const
  • 原文地址:https://www.cnblogs.com/aiwz/p/6153901.html
Copyright © 2011-2022 走看看