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.
# Python program to demonstrate # drop clause import mysql.connector # Connecting to the Database mydb = mysql.connector.connect( host ='localhost', database ='College', user ='root', ) cs = mydb.cursor() # drop clause statement = "Drop Table if exists Employee" # Uncommenting statement ="DROP TABLE employee" # Will raise an error as the table employee # does not exists cs.execute(statement) # Disconnecting from the database mydb.close() |
Output:

Example 2: Program to drop table Geeks
# Python program to demonstrate # drop clause import mysql.connector # Connecting to the Database mydb = mysql.connector.connect( host ='localhost', database ='College', user ='root', ) cs = mydb.cursor() # drop clause statement ="DROP TABLE Geeks" cs.execute(statement) # Disconnecting from the database mydb.close() |
Output:

Recommended Posts:
- Connect MySQL database using MySQL-Connector Python
- Python: MySQL Create Table
- Python MySQL - Insert into Table
- Display the Pandas DataFrame in table style and border around the table and not around the rows
- MongoDB python | Delete Data and Drop Collection
- Python | Delete rows/columns from DataFrame using Pandas.drop()
- Python | Pandas Index.drop()
- Python | Pandas Series.drop()
- Python | Drop-down list in kivy using .kv file
- Python - Channel Drop using Pillow
- Drop Collection if already exists in MongoDB using Python
- PyQt5 ComboBox – User entered items not stored in drop down menu
- How to drop one or multiple columns in Pandas Dataframe
- Drop rows from the dataframe based on certain condition applied on a column
- How to Drop Rows with NaN Values in Pandas DataFrame?
- PyQt5 - How to hide the items from drop down box in Combo Box
- PyQt5 - Checking if drop down items are hidden or not in ComboBox
- PyQt5 - Setting tool tip to the view (drop-down) part of ComboBox
- PyQt5 - Setting tool tip duration to the view(drop-down) part of the ComboBox
- PyQt5 - Access tooltip duration to view(drop-down) of ComboBox
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

