I am using pyodbc to create or drop table. And I wrote a function to drop table if table has already existed. Please look at my syntax below
try:
cur.execute('Drop table {}'.format(table_name))
except ProgrammingError:
cur.execute(create_table)
However, I got error message :
<ipython-input-79-fe0fe29a1e8e> in upload_to_SQL(file_name, skiprows, table_name)
26 try:
27 cur.execute('Drop table {}'.format(table_name))
--->28 except ProgrammingError:
29 cur.execute(create_table)
30
NameError: name 'ProgrammingError' is not defined
I confirm that ProgrammingError is the error message if I drop a table didn't exist in the sql server. Anyone have idea how to revise this?