oracle 建立简单表,id自增

select *from STUDENT
 drop table STUDENT (删除表结构)
truncate  table  Student   (不能删除表结构,删除所有数据)

insert into STUDENT (NAME, SEX, HOBBY, CLASSES, GRADE)
values ( 'weng22', 'nv', '排球', '高二', 98);

create table STUDENT
( ID NUMBER(6)  PRIMARY KEY,
  NAME    VARCHAR2(20),
  SEX     VARCHAR2(20),
  HOBBY   VARCHAR2(20),
  CLASSES VARCHAR2(20),
  GRADE   NUMBER(6)
)
tablespace USERS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );


    drop sequence dectuser_tb_seq;  
    
      create sequence dectuser_tb_seq minvalue 1 maxvalue 99999999  
               increment by 1  
               start with 1;
    
    
    create or replace trigger dectuser_tb_tri    
   before insert on STUDENT
   for each row      
begin    
select  dectuser_tb_seq.nextval into :new.id from dual; 
  
end;  

你可能感兴趣的:(oracle,oracle)