首页 > 数据库技术 > 详细

PostgreSQL的sequence小例子

时间:2015-08-27 19:28:04      阅读:203      评论:0      收藏:0      [点我收藏+]


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 行记录)



PostgreSQL的sequence小例子

原文:http://my.oschina.net/liuyuanyuangogo/blog/498208

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!