GBase 8c
运维管理
文章
GBbase 8c 序列管理
发表于2026-03-19 18:19:3810次浏览3个评论
--- (1)方式一: 声明字段类型为序列整型来定义标识符字段
--- 创建数据表,指定 serial 类型
drop table if exists SEQ_T1 CASCADE;
CREATE TABLE SEQ_T1
(
id serial,
name text
);
--- 插入数据,只插入 name 列
insert into SEQ_T1 (name) values('a1'),('a2'),('a3'),('a4'),('a5'),('a6');
--- 查询表的序列值
select * from SEQ_T1 order by id;
--- (2)方式二: CREATE SEQUENCE 创建序列
--- 创建序列
drop sequence if exists seq1 CASCADE;
create sequence seq1 INCREMENT 1 MINVALUE 1 MAXVALUE 100 START 1 ;
--- 指定为某一字段的默认值,使该字段具有唯一标识属性。
drop table if exists SEQ_T2 CASCADE;
CREATE TABLE SEQ_T2
(
id int not null default nextval('seq1'),
name text
);
--- 插入数据,只插入 name 列
insert into SEQ_T2 (name) values('b1'),('b2'),('b3'),('b4');
--- 查询表的序列值
select * from SEQ_T2 order by id;
评论
登录后才可以发表评论
热门帖子
- 12025-12-01浏览数:182759
- 22023-05-09浏览数:25044
- 42023-09-25浏览数:18519
- 52020-05-11浏览数:17526