序列

直接使用序列类型

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;

posted @ 2018-10-22 15:37  岳麓丹枫  阅读(89)  评论(0编辑  收藏  举报