Drop table if exists : Drop Table « Table Index « SQL / MySQL






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>

   
    
    
    
    
    
    
  








Related examples in the same category

1.Dropping Databases
2.In MySQL, a single DROP TABLE statement can name several tables to be dropped simultaneously
3.Add an IF EXISTS clause to the drop table statement
4.Drop more than one table at single statement