DROP TABLE
is a MySQL command used to delete a table and its associated data, indexes, and privileges permanently.
The syntax of the command is as follows:
DROP TABLE table_name;
Where table_name
is the name of the table you want to delete.
When you execute the DROP TABLE
command, it removes the specified table from the database permanently, and you cannot retrieve the data or the structure of the table after that.
You can use this command to delete any table, including those with primary key and foreign key constraints.
Before using the DROP TABLE
command, ensure that you have a backup of the table or database, or you have exported the table data to a file, in case you need to retrieve the data later.
DROP DATABASE
is a MySQL command used to delete a database and its associated tables, data, indexes, and privileges permanently. The syntax of the command is as follows:
DROP DATABASE database_name;
Where database_name
is the name of the database that you want to delete.
What is in table friends:
mysql> SELECT * FROM friends;
Empty set (0.00 sec)
mysql> DESCRIBE friends;
+-----------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| Name | char(30) | YES | | NULL | |
| Lastname | char(30) | YES | | NULL | |
| Telephone | int | YES | | NULL | |
+-----------+----------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
mysql>
We will delete it:
mysql> DROP TABLE friends;
Query OK, 0 rows affected (1.04 sec)
mysql>
After executing the DROP TABLE
command, if you try to select data from the friends
table, you will receive an "Empty set" message, indicating that the table no longer exists in the database.
mysql> SHOW TABLES IN test;
Empty set (0.00 sec)
mysql>
We will delete database test:
mysql> DROP DATABASE test;
Query OK, 0 rows affected (0.16 sec)
mysql>
Now we have default situation in MySQL:
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.03 sec)
mysql>
Do BACKUPS of important data bafore using DROP command !!!
No comments:
Post a Comment