PostgreSQL的sequence小例子

前端之家收集整理的这篇文章主要介绍了PostgreSQL的sequence小例子前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


highgo=#createsequencet_seqincrementby1startwith1;
CREATESEQUENCE
highgo=#selectnextval('t_seq');--查看序列中下一个值
nextval
---------
1
(1行记录)

highgo=#createtablet(idintdefaultnextval(‘t_seq’),namevarchar);--在定义时使用sequence
CREATETABLE
highgo=#insertintot(name)values('jasmine'),('lily');
INSERT02
highgo=#select*fromt;
id|name
----+---------
2|jasmine
3|lily
(2行记录)

highgo=#createtablet1(idint,namevarchar);
CREATETABLE
highgo=#selectnextval('t_seq');
nextval
---------
6
(1行记录)
highgo=#insertintot1values(nextval('t_seq'),'jim');--在插入int数值时使用sequence
INSERT01
highgo=#select*fromt1;
id|name
----+------
7|jim
(1行记录)

猜你在找的Postgre SQL相关文章