暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Sequence序列号

原创 王三又 2020-07-08
640

A sequence:
Can automatically generate unique numbers
is a shareable object
Can be used to create a primary key value
Replaces application code
Speeds up the efficiency of accessing sequence values when cached in memory

CREATE SEQUENCE 序列名
[INCREMENT BY n]增长值
[START WITH n]第一个值
[(MAXVALUE n | NOMAXVALUE)]最大
[(MINVALUE n | NOMINVALUE)]是否包含最小
[(CYCLE | NOCYCLE) ]循环使用,不建议
[(CACHE n | NOCACHE) ]内存一次性装在几个,系统崩溃后出错

引用序列号NEXTVAL and CURRVAL Pseudocolun
· NEXTVAL returns the next available sequence value.It returns a unique value everytime it is referenced, even for different users.
· CURRVAL obtains the current sequence value.
· NEXTVAL must be issued for that sequence before CURRVAL contains a value.
Insert a new department named“Support”in location ID 2500:

View the current value for the DEPT_DEPTID_SEQ sequence:

Caching Sequence Values
· Caching sequence values in memory gives faster access to those values.
· Gaps in sequence values can occur when:序列号断层
—A rollback occurs
—The system crashes
—A sequence is used in another table
Guidelines for Modifying a Sequence

ALTER SEQUENCE 序列名
[INCREMENT BY n]
[START WITH n]不能修改初始值,必须先删除
[(MAXVALUE n | NOMAXVALUE)]
[(MINVALUE n | NOMINVALUE)]
[(CYCLE | NOCYCLE) ]
[(CACHE n | NOCACHE) ]

· You must be the owner or have the ALTER privilege for the sequence.
· Only future sequence numbers are affected.
· The sequence must be dropped and re-created to restart the sequence at a different number.
· Some validation is performed.
· To remove a sequence, use the DROP statement:

DROP SEQUENCE dept_dept id_seq;

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论