MySQL Drop Table

It is very easy to drop an existing MySQL table, but you need to be very careful while deleting any existing table because the data lost will not be recovered after deleting a table.


Here is a generic SQL syntax to drop a MySQL table −

DROP TABLE table_name ;

Dropping Tables from the Command Prompt
To drop tables from the command prompt, we need to execute the DROP TABLE SQL command at the mysql> prompt.

The following program is an example which deletes the student table from the school database

root@host# mysql -u root -p
Enter password:*******
mysql> use SCHOOL;
Database changed
mysql> DROP TABLE student
Query OK, 0 rows affected (0.8 sec)

Drop Table Using Python Script

To drop an existing table in any database, you would need to use the PHP function mysql_query(). You will pass its second argument with a proper SQL command to drop a table.


import mysql.connector
conn = mysql.connector.connect(host='localhost',user='root',password='',database="school")
cursor = conn.cursor()
cursor.execute('drop table student;')
print('Table deleted successfully')
Print Friendly, PDF & Email

Related Posts

If you like CBSEToaday and would like to contribute, you can also write an article using submit article or mail your article to See your article appearing on the main page and help other students/teachers.