---- 创建表
create table t_student
(
id number(10) not null,
createtime date not null,
constraint pk_t_student primary key (id)
)
---添加注释
comment on table t_student is '学生表';
comment on t_student.id is '学号';
comment on t_student.createtime is '创建时间';
--- 创建序列,用来生成自增主键
create sequence seq_t_student
minvalue 1 ----最小值
nomaxvalue ----没有最大值
start with 1 ----从1开始
increment by 1 ----每次增加1
nocycle ----一直增加,不循环
cache 10; ----缓存10条
--- 创建触发器,以用来使用已创建好的序列来生成主键
create or replace trigger t_s_student
before insert on t_student for each row
when(new.id is null)
begin
select seq_t_student.nextval into :new.id from dual;
end;