Sequences is used to generate primary key value. In MySQL, you can create a column that contains a sequence of numbers (set of integers 1, 2, 3, and so on that are generated in order on a specific demand.) by using the AUTO_INCREMENT attribute. The AUTO_INCREMENT attribute is used when you need to create a unique number to act like a primary key in a table.
below are the syntax to create a sequence (or use the AUTO_INCREMENT attribute) in MySQL is:
CREATE TABLE table_name ( column1 datatype NOT NULL AUTO_INCREMENT, column2 datatype [ NULL | NOT NULL ], ... );
- AUTO_INCREMENT : The attribute to use when you want MySQL to assign a sequence of numbers automatically to a field.
- NULL or NOT NULL : Each column should be defined as NULL or NOT NULL. If this parameter is omitted, the database assumes NULL as the default.