Primary key
Why?
Regular indexes do not impose the values to be unique!
The importance of having a key with a unique value for each row will come up when we start to combine data from different tables.
Create
By adding the PRIMARY KEY(column_name) at the end of CREATE TABLE.
CREATE TABLE artist (
id MEDIUMINT(4) NOT NULL AUTO_INCREMENT,
fname VARCHAR(20) DEFAULT NULL,
lname VARCHAR(20) NOT NULL,
PRIMARY KEY(id)
);
Resulting in:
+---------+--------------+--------+-------+-----------+----------------+ | Field | Type | Null | Key | Default | Extra | |---------+--------------+--------+-------+-----------+----------------| | id | mediumint(4) | NO | PRI | <null> | auto_increment | | fname | varchar(20) | YES | | <null> | | | lname | varchar(20) | NO | | <null> | | +---------+--------------+--------+-------+-----------+----------------+
NB! As PRIMARY KEY requires unique values, the NOT NULL and/or AUTO_INCREMENT attribute should be present.