Drop table column with alter table command : Alter Table : Table MySQL TUTORIALS


MySQL TUTORIALS » Table » Alter Table »

 

Drop table column with alter table command


mysql>
mysql>
mysql> CREATE TABLE myTable(
    ->    ID SMALLINT
    -> );
Query OK, rows affected (0.03 sec)

mysql>
mysql> desc myTable;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| ID    | smallint(6| YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
row in set (0.02 sec)

mysql>
mysql> ALTER TABLE myTable
    ->    ADD COLUMN Quantity SMALLINT UNSIGNED NOT NULL,
    ->    MODIFY ID SMALLINT UNSIGNED NOT NULL,
    ->    ADD PRIMARY KEY (ID);
Query OK, rows affected (0.06 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>
mysql> desc myTable;
+----------+----------------------+------+-----+---------+-------+
| Field    | Type                 | Null | Key | Default | Extra |
+----------+----------------------+------+-----+---------+-------+
| ID       | smallint(5unsigned | NO   | PRI |         |       |
| Quantity | smallint(5unsigned | NO   |     |         |       |
+----------+----------------------+------+-----+---------+-------+
rows in set (0.00 sec)

mysql>
mysql> ALTER TABLE myTable
    ->    DROP COLUMN Quantity,
    ->    DROP PRIMARY KEY;
Query OK, rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>
mysql> desc myTable;
+-------+----------------------+------+-----+---------+-------+
| Field | Type                 | Null | Key | Default | Extra |
+-------+----------------------+------+-----+---------+-------+
| ID    | smallint(5unsigned | NO   |     |         |       |
+-------+----------------------+------+-----+---------+-------+
row 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
» Alter Table