0
点赞
收藏
分享

微信扫一扫

序列


直接使用序列类型

create table test (id serial, name varchar(10));

间接使用

  • 创建序列

 CREATE SEQUENCE seq_test
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1
CYCLE; // 循环,表示到最大值后从头开始

SELECT * FROM information_schema.sequences WHERE sequence_name='seq_test';

  • 创建表,使用序列

create table tbl_test
(
id int not null DEFAULT nextval('seq_test'),
name varchar(10)
);

  • 插入数据

insert into tbl_test(name) values('a'),('b'),('c');

  • 查询数据

select * from tbl_test;


举报

相关推荐

0 条评论