Add Unique constaints to cover two columns : Unique : Table MySQL TUTORIALS


MySQL TUTORIALS » Table » Unique »

 

Add Unique constaints to cover two columns


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

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

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



Leave a Comment / Note


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

Follow Navioo On Twitter

MySQL TUTORIALS

 Navioo Table
» Unique