MySQL DROP a TABLE and DATABASE
Showing existing databases
The SHOW DATABASES statement used to retrieve the existing databases. This statement returns the databases that are currently in the MySQL server, and the results are useful to avoid the conflicts while creating a new database.
mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| DB                 |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.01 sec)
Use database and show tables
The USE statement notifies MySQL to use the mentioned database for subsequent database and table operations.
mysql> USE DB;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> SHOW TABLES;
+--------------+
| Tables_in_DB |
+--------------+
| holders      |
+--------------+
1 row in set (0.01 sec)

mysql> SELECT * FROM holders;
+-------------+---------------+---------+------------+----------+--------+
| account_no  | name          | city    | dob        | bank     | amount |
+-------------+---------------+---------+------------+----------+--------+
| 25622348989 | James Moore   | Phoenix | 1985-05-26 | Barclays |   5000 |
| 25622348990 | Donald Taylor | Irvine  | 1990-08-20 | Citi     |   7000 |
| 25622348991 | Edward Parkar | Irvine  | 1994-01-29 | ICICI    |  95000 |
| 25622348992 | Ryan Bakshi   | Mumbai  | 1982-01-14 | Citi     |  50000 |
| 25622348993 | Marie Peters  | Ribe    | 1967-01-05 | DZBank   |  12250 |
| 25622348994 | Aanya         | Delhi   | 1975-08-18 | SBI      | 105000 |
+-------------+---------------+---------+------------+----------+--------+
6 rows in set (0.00 sec)
Drop table
The DESCRIBE statement used to obtain information about the table structure. The DROP TABLE statement drops a specified table and its data permanently.
mysql> DESC holders;
+------------+-------------+------+-----+---------+-------+
| Field      | Type        | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| account_no | bigint(20)  | NO   | PRI | NULL    |       |
| name       | varchar(30) | NO   |     | NULL    |       |
| city       | varchar(20) | YES  |     | NULL    |       |
| dob        | date        | YES  |     | NULL    |       |
| bank       | varchar(10) | YES  |     | NULL    |       |
| amount     | bigint(20)  | NO   |     | NULL    |       |
+------------+-------------+------+-----+---------+-------+
6 rows in set (0.01 sec)

mysql> DROP TABLE holders;
Query OK, 0 rows affected (0.42 sec)

mysql> DROP TABLE holders;
ERROR 1051 (42S02): Unknown table 'DB.holders'

mysql> DROP TABLE IF EXISTS holders;
Query OK, 0 rows affected, 1 warning (0.37 sec)

mysql> SHOW WARNINGS;
+-------+------+----------------------------+
| Level | Code | Message                    |
+-------+------+----------------------------+
| Note  | 1051 | Unknown table 'DB.holders' |
+-------+------+----------------------------+
1 row in set (0.00 sec)
Drop database
mysql> DROP DATABASE DB;
Query OK, 0 rows affected (0.20 sec)

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
Advertisement