Add Index and primary key to a table in table creation command : Foreign Keys : Table MySQL TUTORIALS


MySQL TUTORIALS » Table » Foreign Keys »

 

Add Index and primary key to a table in table creation command


mysql>
mysql> CREATE TABLE myTable
    -> (
    ->    OrderID SMALLINT UNSIGNED NOT NULL,
    ->    ModelID SMALLINT UNSIGNED NOT NULL,
    ->    PRIMARY KEY (OrderID),
    ->    INDEX (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   | MUL |         |       |
+---------+----------------------+------+-----+---------+-------+
rows in set (0.00 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
» Foreign Keys