drop table T_USER; commit; --创建数据表 create table T_USER( User_Id int not null PRIMARY KEY, User_Name varchar(20) not null, Age int not null, sex varchar(5) not null, phone varchar(20) not null, address varchar(60) not null ); commit; --序列名字 CREATE SEQUENCE SEQNAME_1 --每次自增1, 也可写非0的任何整数,表示自增,或自减 INCREMENT BY 1 --以该值开始自增或自减 START WITH 1 --最大值;设置NOMAXVALUE表示无最大值 MAXVALUE 10000 --最小值;设置NOMINVALUE表示无最大值 MINVALUE 1 --指定可以缓存 20 个值在内存里;如果设置不缓存序列,则写NOCACHE CACHE 20 ; ---- alter table T_USER add(creatdate DATE default sysdate not null); commit; ------- create or replace trigger dectuser_tb_tri /*触发条件:当向表dectuser执行插入操作时触发此触发器*/ before insert on T_USER /*对每一行都检测是否触发*/ for each row /*触发器开始*/ begin select SEQNAME_1.nextval into :new.User_Id from dual; /*触发器主题内容,即触发后执行的动作,在此是取得序列SEQNAME_1的下一个值插入到表T_USER中的userid字段中*/ end; / ------- insert into T_USER(User_Name,Age,sex,phone,address) values ('TSZR',23,'男','12345678912','地球村'); insert into T_USER(User_Name,Age,sex,phone,address) values ('蓝天白云',23,'男','12345678911','蓝天村'); insert into T_USER(User_Name,Age,sex,phone,address) values ('晚霞',18,'女','12345678900','晚霞村'); commit;