Create SEQUENCE in MySql
by Sanju[ Edit ] 2008-05-30 11:20:26
We cannot able to create SEQUENCE in MYSQL. We can create SEQUENCE only in SQL.
We can use AUTO_INCREMENT in MYSQL instead of using SEQUENCE.
AUTO_INCREMENT is used to increase the value. By default it will increase by 1.
AUTO_INCREMENT_INCREMENT and
AUTO_INCREMENT_OFFSET are intended for use with master-to-master replication, and can be used to control the operation of AUTO_INCREMENT columns.
mysql>show variables like 'auto_inc%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 0 |
| auto_increment_offset | 0 |
+--------------------------+-------+
Syntax:
AUTO_INCREMENT_INCREMENT
mysql> SET @@auto_increment_increment=10;
mysql>show variables like 'auto_inc%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 10 |
| auto_increment_offset | 0 |
+--------------------------+-------+
AUTO_INCREMENT_OFFSET
mysql> SET @@auto_increment_offset=5;
mysql>show variables like 'auto_inc%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 10 |
| auto_increment_offset | 5 |
+--------------------------+-------+
You can also set auto_increment value from creating table,
CREATE TABLE test(a int Unique NOT NULL auto_increment)auto_increment=2;