Primary Keys and Auto Increment Fields in MySQL
Primary key is used to uniquely identify a row in a table. Usually the primary key is an integer value that could be an auto incremented value. The primary key column can also be a combination of two columns.
The column that is identified for PRIMARY key is defined in the schema as:
PRIMARY KEY (employee_id)
When a column is set to “Auto Increment”, its value is automatically incremented in a sequence when a new row is inserted.
Primary Keys and Auto Increment Fields in MySQLPrimary Key:
A primary key is used to uniquely identify a row in a table. A table can have only one primary key. The values in a single column to store primary key are unique. More one column can be used as a primary key. When used, the combination of column values must be unique.Auto Increment attribute:
The Auto Increment attribute is used to generate unique values for new rows. Value once used by a row, can not be used for another row.
The following example illustrates the use of both primary key and auto increment attribute.
CREATE TABLE Products (
id NOT NULL AUTO_INCREMENT,
product_name CHAR(30) NOT NULL,
PRIMARY KEY (id)