Mega Code Archive

 
Categories / MySQL / Table Index
 

Drop table if exists

mysql> mysql> # create a table called "dogs" with 2 columns mysql> CREATE TABLE IF NOT EXISTS dogs     -> (     ->   id INT,     ->   breed TEXT     -> ); Query OK, 0 rows affected (0.00 sec) mysql> mysql> # show that the table has been created mysql> SHOW TABLES; +----------------+ | Tables_in_test | +----------------+ | dogs           | | indexes        | | number_sets    | | time_table     | +----------------+ 4 rows in set (0.00 sec) mysql> mysql> # confirm the "dogs" table format mysql> EXPLAIN dogs; +-------+---------+------+-----+---------+-------+ | Field | Type    | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | id    | int(11) | YES  |     | NULL    |       | | breed | text    | YES  |     | NULL    |       | +-------+---------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> mysql> # delete the "dogs" and "fruit" tables mysql> DROP TABLE IF EXISTS dogs, fruit; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> mysql> # show that the tables have been deleted mysql> SHOW TABLES; +----------------+ | Tables_in_test | +----------------+ | indexes        | | number_sets    | | time_table     | +----------------+ 3 rows in set (0.00 sec) mysql> mysql>