Create primary key after column definition : PRIMARY KEY : Table MySQL TUTORIALS


MySQL TUTORIALS » Table » PRIMARY KEY »

 

Create primary key after column definition


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

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

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



Leave a Comment / Note


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

Follow Navioo On Twitter

MySQL TUTORIALS

 Navioo Table
» PRIMARY KEY