Sequence是数据库系统按照一定规则自动增加的数字序列。这个序列一般作为代理
主键(因为不会重复),没有其他任何意义。
Sequence是数据库系统的特性,有的数据库有Sequence,有的没有。比如Oracle、
DB2、PostgreSQL数据库有Sequence,MySQL、SQL Server、Sybase等数据库没有
Sequence。
根据我个人理解,Sequence是数据中一个特殊存放等差数列的表,该表受数据库系
统控制,任何时候数据库系统都可以根据当前记录数大小加上步长来获取到该表下
一条记录应该是多少,这个表没有实际意义,常常用来做主键用,非常不错,呵呵
,不过很郁闷的各个数据库厂商尿不到一个壶里--各有各的一套对Sequence的定义
和操作。在此我对常见三种数据库的Sequence的定义和操作做一个对比和总结,以
便日后查看。
一、定义Sequence
定义一个seq_test,最小值为10000,最大值为99999999999999999,从20000开始
,增量的步长为1,缓存为20的循环排序Sequence。
Oracle的定义方法:
create sequence seq_test
minvalue 10000
maxvalue 99999999999999999
start with 20000
increment by 1
cache 20
cycle
order;
DB2的写法:
create sequence seq_test
as bigint
start with 20000
increment by 1
minvalue 10000
maxvalue 99999999999999999
cycle
cache 20
order;
PostgreSQL的写法:
create sequence seq_test
increment by 1
minvalue 10000
maxvalue 99999999999999999
start 20000
cache 20
cycle;
二、Oracle、DB2、PostgreSQL数据库Sequence值的引用参数为:currval、
nextval,分别表示当前值和下一个值。下面分别从三个数据库的Sequence中获取
nextval的值。
Oracle中:seq_test.nextval
例如:select seq_test.nextval from dual;
DB2中:nextval for SEQ_TOPICMS
例如:values nextval for seq_test;
PostgreSQL中:nextval(seq_test)
例如:select nextval(seq_test);
三、Sequence与indentity的区别与联系
Sequence与indentity的基本作用都差不多。都可以生成自增数字序列。
Sequence是数据库系统中的一个对象,可以在整个数据库中使用,和表没有任何关
系;indentity仅仅是指定在表中某一列上,作用范围就是这个表。
分享到:
相关推荐
在Oracle数据库中,sequence等同于序列号,每次取的时候sequence会自动增加,一般会作用于需要按序列号排序的地方。 1、Create Sequence (注释:你需要有CREATE SEQUENCE或CREATE ANY SEQUENCE权限) CREATE ...
A method for assembly sequence planning is proposed in this paper. First, two methods for assembly sequence planning are compared, which are indirect method and direct method. Then, the limits of the ...
基于循环神经网络和注意力机制的Sequence-to-Sequence模型神经网络方法在信息抽取和自动摘要生成方面发挥了重要作用。然而,该方法不能充分利用文本的语言特征信息,且生成结果中存在未登录词问题,从而影响文本摘要...
SequenceDiagram-3.0.5.zip
在Oracle数据库移植过程中,sequence可能失效,本资源可使失效的sequence重新恢复作用
时序图(SequenceDiagram)是显示对象之间交互的图,这些对象是按时间顺序排列的。顺序图中显示的是参与交互的对象及其对象之间消息交互的顺序。时序图中包括的建模元素主要有:对象(Actor)、生命线(Lifeline)、...
memory networks, are extremely appealing for sequence-tosequence learning tasks. Despite their great success, they typically suffer from a fundamental shortcoming: they are prone to generate ...
Sequence to Sequence Learning with Neural Networksv论文PDF版
invalid multibyte character sequence 870告警1
机器学习之sequence to sequence learning。(Sequence Generation-----Hung-yi Lee 李宏毅.ppt)
Matlab产生m序列的函数-m_sequence1.m 一个产生m序列的函数,希望大家喜欢 function [mseqmatrix]= m_sequence1; n = length; N = 2^n-1; register = [zeros 1];%定义移位寄存器的初始状态 mseqmatrix= ...
Edward Grefenstette - Beyond Sequence to Sequence with Augmented RNNs
sequence-diagram-js 所需jar包,其中sequence-diagram-js支持自定义颜色
oracle中sequence介绍及应用
解决Invalid byte 1 of 1-byte UTF-8 sequence
The result is a flexible and broadly useful class of neural network models that has favorable inductive biases relative to purely sequence-based models (e.g., LSTMs) when the problem is graph-...
Sequence Diagrams of UML
搜狐2017笔试题一:Kolakoski sequence完整源代码
Informatica中Sequence Generator的两个有用的选项