oracel创建表和自增主键

CREATE TABLE ysb_log(
  id number(8) primary key ,
  tbdate varchar(50)  ,
  tb_time varchar(50) ,
  tblog varchar(500) ,
  tbreor varchar2(20) ,
  bs varchar(50)
);

--创建序列/自增值
create sequence S_ysb_log
  minvalue 1
  maxvalue 99999999
  start with 1
  increment by 1
  NOCYCLE
  nocache;

--建完表和自增值后键一个触发器
create trigger mem_trig before
  insert on ysb_log for each row when (new.id is null)
  begin

    select S_ysb_log.nextval into:new.id from dual;

  end;
-------------------------
insert into  ysb_log (tbdate , tb_time, tblog, tbreor ,bs )
values ( '2016-7-21','10:01:00','dddddd',null, 'OrderDown' );

select * from ysb_log;

 

你可能感兴趣的:(oracel创建表和自增主键)