Google News
logo
Python Program to Delete an Existing Table
To delete an existing table in MySQL using Python, you can use the following program :
Program :
import mysql.connector

# Establishing connection to the database
mydb = mysql.connector.connect(
  host="localhost",
  user="yourusername",
  password="yourpassword",
  database="yourdatabase"
)

# Creating a cursor object
mycursor = mydb.cursor()

# SQL statement to delete a table
sql = "DROP TABLE yourtable"

# Executing the SQL command
mycursor.execute(sql)

# Commit the changes to the database
mydb.commit()

# Closing the database connection
mydb.close()

print("Table deleted successfully!")
Note: Replace `yourusername`, `yourpassword`, `yourdatabase`, and `yourtable` with your own values. Also, be careful while deleting a table as all the data in that table will be lost permanently.