A connector is employed when we have to use MySQL with other programming languages. The work of MySQL-connector is to provide access to MySQL Driver to the required language. Thus, it generates a connection between the programming language and the MySQL Server.
Drop Table Command
Drop command affects the structure of the table and not data. It is used to delete an already existing table. For cases where you are not sure if the table to be dropped exists or not DROP TABLE IF EXISTS command is used. Both cases will be dealt with in the following examples. Syntax:
DROP TABLE tablename;
DROP TABLE IF EXISTS tablename;
The following programs will help you understand this better. Tables before drop:
Example 1: Program to demonstrate drop if exists. We will try to drop a table which does not exist in the above database.
Python3
import mysql.connector
mydb = mysql.connector.connect(
host ='localhost',
database ='College',
user ='root',
)
cs = mydb.cursor()
statement = "Drop Table if exists Employee"
cs.execute(statement)
cs.commit()
mydb.close()
|
Output:
Example 2: Program to drop table Geeks
Python3
import mysql.connector
mydb = mysql.connector.connect(
host ='localhost',
database ='College',
user ='root',
)
cs = mydb.cursor()
statement ="DROP TABLE Geeks"
cs.execute(statement)
cs.commit()
mydb.close()
|
Output: 
Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.
Last Updated :
28 Feb, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...