sql序列什么意思_什么是SQL序列?
sql 序列什么意思
Sequence is a feature supported by some database systems to produce unique values on demand. Some DBMS like Sequence
MySQL supports AUTO_INCREMENT in place of Sequence.
MySQL
MySQL)⽀持AUTO_INCREMENT代替Sequence。
序列是某些数据库系统⽀持的功能,可以按需⽣成唯⼀值。 ⼀些DBMS(例如MySQL)
序列
AUTO_INCREMENT is applied on columns, it automatically increments the column value by 1 each time a new record is inserted into the table.
AUTO_INCREMENT应⽤于列,每次将新记录插⼊表中时,列值都会⾃动增加1 。
Sequence is also some what similar to AUTO_INCREMENT but it has some additional features too.
序列也与AUTO_INCREMENT类似,但也具有⼀些其他功能。
创建⼀个序列 (Creating a Sequence)
Syntax to create a sequence is,
创建序列的语法是
CREATE SEQUENCE sequence-name
START WITH initial-value
INCREMENT BY increment-value
MAXVALUE maximum-value
CYCLE | NOCYCLE;
The initial-value
initial-value specifies the starting value for the Sequence.
初始值指定序列的起始值。
初始值
increment-value is the value by which sequence will be incremented.
The increment-value
递增的值 。
增量值是将序列递增的值
增量值
maximum-value specifies the upper limit or the maximum value upto which sequence will increment itself.
The maximum-value
最⼤值指定序列将⾃⾏递增的上限或最⼤值。
最⼤值
The keyword CYCLE specifies that if the maximum value exceeds the set limit, sequence will restart its cycle from the begining.
关键字CYCLE指定如果最⼤值超过设置的限制,则序列将从头开始重新开始其循环。
And, NO CYCLE specifies that if sequence exceeds MAXVALUE value, an error will be thrown.
并且, NO CYCLE指定如果序列超过MAXVALUE值,将引发错误。
在SQL查询中使⽤序列 (Using Sequence in SQL Query)
record是什么意思中文Let's start by creating a sequence, which will start from 1, increment by 1 with a maximum value of 999.
让我们从创建⼀个序列开始,该序列将从1开始,以1为增量,最⼤值为999 。
CREATE SEQUENCE seq_1
START WITH 1
INCREMENT BY 1
MAXVALUE 999
CYCLE;
Now let's use the sequence that we just created above.
现在,使⽤上⾯刚刚创建的序列。
class table,
Below we have a class
类表,
下⾯有⼀个类
ID NAME
1abhi
2adam
4alex
ID名称
1个阿⽐
2亚当
4亚历克斯
The SQL query will be,
SQL查询将是
INSERT INTO class VALUE(val, 'anu');
Resultset table will look like,
结果集表如下所⽰:
ID NAME
1abhi
2adam
4alex
1anu
ID名称
1个阿⽐
2亚当
4亚历克斯
1个阿努
Once you use nextval the sequence will increment even if you don't Insert any record into the table.
⼀旦使⽤nextval ,即使您没有在表中插⼊任何记录,序列也会递增。sql 序列什么意思
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论