MySQL - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

MySQL Sequences

MySQL Sequences

shape Description

MySQL Sequence are the arrangement of whole numbers that are created all together based on appeal. Sequence will be regularly utilized as a part of databases considering numerous applications requirement that every column in a table to contain an interesting worth and these sequences will be accessible easily.

Auto increment column

shape Description

The least complex route in MySQL is to utilize sequence to characterize a segment as AUTO_INCREMENT and authorize the remaining features to MySQL.

shape Conceptual figure

  • Sequence - Is a user defined datatype which is used to increment the values accordingly.
  • Application user - Who performs on specific tasks.
  • Tables - Is a logical sequence which is used to arrange the data in row and column format.

shape Syntax

create table <table_name> (<column_name1>data type(size) constraint type, <column_name2>data type(size),constraint(column_name1);
table_name => Any accurate table. column_name => The operation that can be performed in the column of a table. constraint_type =>constraint type will specify the type of constraint, that going to be executed in the database.

shape Examples

By viewing the below example, the concept of Primary Key constraint can be easily understand. [sql]mysql> create table product(prod_id int not null auto_increment,prod_name varchar (255)not null,primary key(prod_id)); Query OK, 0 rows affected (0.52 sec) mysql> insert into product (prod_name) values ('mobile'); Query OK, 1 row affected (0.05 sec) mysql> insert into product (prod_name) values ('laptop'); Query OK, 1 row affected (0.09 sec) mysql> insert into product (prod_name) values ('system'); Query OK, 1 row affected (0.09 sec) mysql> select * from product; +---------+-----------+ | prod_id | prod_name | +---------+-----------+ | 1 | mobile | | 2 | laptop | | 3 | system | +---------+-----------+ 3 rows in set (0.00 sec)[/sql] In the above example, the column prod_id is given not null auto increment constraint and at the same time in another column prod_id is given primary key constraint. In such case, no need to insert each an every value. Just write the prod_name it will automatically display the prod_id values.

Summary

shape Key Points

  • MySQL Sequence - Set of whole number that are generated based on the demand.