0

HI all i am trying to delete the contents of my tabel before entering new data and i cant seem to get it to work , i keep on getting a error or is there a better way then i am trying to do it, here is the code thank you all for your help in advance

import mysql.connector
import pandas as pd
import mysql.connector
from mysql.connector import Error



print ("Clearning Flight Data table for new data")


try:
    connection = mysql.connector.connect(host='localhost',
                                         database='flightdata',
                                         user='root',
                                         password='*****')
    cursor = connection.cursor()
    Delete_all_rows = """flightinfo """
    cursor.execute(Delete_all_rows)
    connection.commit()
    print("All Record Deleted successfully ")

except mysql.connector.Error as error:
    print("Failed to Delete all records from database table: {}".format(error))
finally:
    if (connection.is_connected()):
        cursor.close()
        connection.close()
        print("MySQL connection is closed")


print ("Running Sydney KWS Domestic update")
import syd_kws_dom


print ("Running Sydney KWS International update")
import syd_kws_int
2
  • Have you tried this? cursor.execute('delete from flightinfo'). Commented Nov 18, 2019 at 2:15
  • that seemed to work mate so i dont need the delete_all_rows? Commented Nov 18, 2019 at 2:18

1 Answer 1

1
  • you can just execute delete query using cursor.execute.
Delete_all_rows = """delete from flightinfo """
cursor.execute(Delete_all_rows)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.