Use two columns as the combined primary key : PRIMARY KEY : Table MySQL TUTORIALS


MySQL TUTORIALS » Table » PRIMARY KEY »

 

Use two columns as the combined primary key


mysql>
mysql> CREATE TABLE myTable
    -> (
    ->    OrderID     SMALLINT UNSIGNED NOT NULL,
    ->    ModelID     SMALLINT UNSIGNED NOT NULL,
    ->    Description VARCHAR(40),
    ->    PRIMARY KEY (OrderID, ModelID)
    -> );
Query OK, rows affected (0.03 sec)

mysql>
mysql> desc myTable;
+-------------+----------------------+------+-----+---------+-------+
| Field       | Type                 | Null | Key | Default | Extra |
+-------------+----------------------+------+-----+---------+-------+
| OrderID     | smallint(5unsigned | NO   | PRI |         |       |
| ModelID     | smallint(5unsigned | NO   | PRI |         |       |
| Description | varchar(40)          | YES  |     | NULL    |       |
+-------------+----------------------+------+-----+---------+-------+
rows in set (0.02 sec)

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

mysql>



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

MySQL TUTORIALS

 Navioo Table
» PRIMARY KEY