The correct way to open the oracle table

--oracle建表
drop table gxdw;
CREATE TABLE gxdw(
  id number(11) constraint pk_si_id primary key,
  departcode varchar2(20),
  departname varchar2(20),
  departlevel varchar2(20),
  parentdepartcode varchar2(20),
  remarks varchar2(20),
  update_time date,
  is_delete number(1) default 0
);

comment on table gxdw is 'jurisdictional unit';
comment on column gxdw.id is 'id';
comment on column gxdw.departcode is 'department code';
comment on column gxdw.departname is 'department name';
comment on column gxdw. departurelevel is 'department level';
comment on column gxdw.parentdepartcode is 'parent department code';
comment on column gxdw.remarks is 'remarks';
comment on column gxdw.update_time is 'update time';
comment on column gxdw.is_delete is 'has been deleted';

--Realize auto-increment of primary key
--Step 1: create sequence: create
sequence gxdwID_seq 
  minvalue 1 --minimum value is limited to 1
  maxvalue 9999 --maximum value is limited to
  increment by 1 --each auto-increment 1
  start with 1; -- Start counting from 1
  
  
--Step 2: Create a trigger:
create or replace trigger gxdwID_tri
  before insert on gxdw
  for each row
  begin 
  select gxdwID_seq.Nextval into :new.id from dual;
  end ;
 

Supongo que te gusta

Origin blog.csdn.net/lystest/article/details/130988457
Recomendado
Clasificación