Create SEQUENCE in MySql - Mysql Send mail vote down 0 vote down 1 Views : 3196
Tagged in : Mysql
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;
By - Sanju, On - 2008-05-30




    Login to add Comments .