pg--sequence序列的用例

Posted on 2012-11-06 16:42  JasmineLiu  阅读(695)  评论(0编辑  收藏  举报

6 sequence序列

highgo=# create sequence t_seq increment by 1 start with 1;

CREATE SEQUENCE

highgo=# select nextval('t_seq');   查看序列中下一个值

 nextval

---------

       1

(1 行记录)            

highgo=#create table t(id int default nextval(‘t_seq’),name varchar);    在定义时使用sequence

CREATE TABLE

highgo=# insert into t(name) values('jasmine'),('lily');

INSERT 0 2

highgo=# select * from t;

 id |  name

----+---------

  2 | jasmine

  3 | lily

(2 行记录)

 

 

highgo=# create table t1(id int,name varchar);

CREATE TABLE

highgo=# select  nextval('t_seq');

 nextval

---------

       6

(1 行记录)

highgo=# insert into t1 values(nextval('t_seq'),'jim');  在插入int数值时使用sequence

INSERT 0 1

highgo=# select *  from t1;

 id | name

----+------

  7 | jim

(1 行记录)

Copyright © 2024 JasmineLiu
Powered by .NET 8.0 on Kubernetes