Auto_INCREMENT primary key : PRIMARY KEY « Table « MySQL Tutorial






mysql>
mysql>
mysql> CREATE TABLE myTable
    -> (
    ->    ID SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
    ->    Name VARCHAR(40) NOT NULL,
    ->    PRIMARY KEY (ID)
    -> );
Query OK, 0 rows affected (0.03 sec)

mysql>
mysql> desc myTable;
+-------+----------------------+------+-----+---------+----------------+
| Field | Type                 | Null | Key | Default | Extra          |
+-------+----------------------+------+-----+---------+----------------+
| ID    | smallint(5) unsigned | NO   | PRI | NULL    | auto_increment |
| Name  | varchar(40)          | NO   |     |         |                |
+-------+----------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

mysql>
mysql> drop table myTable;
Query OK, 0 rows affected (0.00 sec)








4.15.PRIMARY KEY
4.15.1.Primary Keys
4.15.2.Create primary key in column definition
4.15.3.Create primary key after column definition
4.15.4.Multiple-Column Primary Keys
4.15.5.Auto_INCREMENT primary key
4.15.6.Use two columns as the combined primary key
4.15.7.Use partial indexing as the primary key
4.15.8.ALTER TABLE table_name ADD PRIMARY KEY index_name (column_name[,...]);
4.15.9.To drop a PRIMARY KEY
4.15.10.To remove a primary key
4.15.11.Alter table to drop primary key and foreign key
4.15.12.Add Index and primary key to a table in table creation command