如上表所示,设置ID为自增
create table students(
id smallint not null constraint pk_id primary key,
name varchar(50) not null,
age int(20),
address varchar(100)
)
查看约束
select * from user_constraints;
创建序列
create sequence students_id_seq start with 1 increment by 1;
查看序列
select * from user_sequences;
创建触发器
create or replace trigger students_trigger
before insert on students
for each row
when(new.id is null)
begin
select students_id_seq.nextval into:NEW.ID from dual;
end;
查看触发器
select * from user_triggers;