1,创建数据库表:
create table t1(
tid number(3) primary key,
tname varchar(10) not null,
tsex varchar(4) not null,
tage number(2) not null,
tnative varchar(16) not null
)
2,创建自动增长序列:
create sequence t1_seq
mixvalue 1 //最小值
maxvalue 9999999999 //最大值
start with 1 //开始值
increment by 1 //增量
cache 20 //缓存量
3,创建触发器:
create or replace trigger t1_trg
2 before insert on t1 //往表(t1)添加值时发
3 for each row //检查每行
4 begin
5 select t1_seq.nextval into :new.tid from dual;//自动生成的字段
6 end;
4,提交:
insert into t1(tname,tsex,tage,tnative)values('刘晓明','女',20,'黑龙江');
commit;
本文详细介绍如何使用SQL语句创建包含自动增长字段的数据库表。通过实例演示了创建表结构、定义字段类型、设置主键约束的过程,并介绍了序列与触发器的创建方法,确保表中每一项记录都有唯一标识。
5029

被折叠的 条评论
为什么被折叠?



