大家好,以前没用过PL/sql developer,有谁知道怎样用工具设置主键自动增长?

解决方案 »

  1.   

    Oracle 里没有这个功能,要创建序列以及触发器
      

  2.   

    --创建序列
    CREATE SEQUENCE pro_su
    INCREMENT BY 1 -- 每次加几个
    START WITH 1 -- 从1开始计数
    NOMAXVALUE -- 不设置最大值
    NOCYCLE -- 一直累加,不循环
    NOCACHE -- 不建缓冲区--创建触发器,调动自增事件
    create or replace trigger trigger_product
    before insert on product 
    for each row
    declare
    next_userid number;
    begin
    select pro_su.nextval into next_userid from dual;
    :new.id :=next_userid;
    end trigger_product;
      

  3.   

    ORACLE没有SQLSERVER那么方便加自增,可以创建序列,根据序列建个触发器
    看一下我的:
    自增序列:
    create sequence SEQ_Tem_Other
    minvalue 1
    maxvalue 999999
    start with 1
    increment by 1
    cache 20; 
    行级触发器:
    create or replace trigger TR_Tem_Other_id
    before insert on T_Tem_Other
    for each row
    begin
      select SEQ_Tem_Other.nextval into :new.id from dual;
    end;
      

  4.   

    我说的是PL/sql developer这个图形化工具有没有这个功能啊?比如在建表时有没有这个选项啊?
      

  5.   

    没见过,一般设计表用powerdesigner,在这个里面做成自增长,其实原理就是创建序列以及触发器但是触发器性能不是很好,所以建议如下:
    create sequence test1Seq --自定义的序列名
    increment by 1           --每次加几个,即递增的间隔
    start with 1             --从1开始计数
    nomaxvalue               --不设置最大值
    nocycle                  --一直累加,不循环
    cache 10;
    ==============================================================
    insert into test1(tid,tname,tbd)values(test1Seq.Nextval,'ccc',sysdate);