How to extract column and table names from SQL using python?
Is there any available solution for SQL parsing?
How to extract column and table names from SQL using python?
Is there any available solution for SQL parsing?
This might be of help, though I haven’t verified the code yet:
import pyodbc
cnxn = pyodbc.connect(databasez)
cursor = cnxn.cursor()
cursor.execute("SELECT * FROM my_table")
columns = [column[0] for column in cursor.description]
cnxn = pyodbc.connect(...)
cursor = cnxn.cursor()
for row in cursor.tables():
print row.table_name
Thanks for sharing your reply. Can we get such data without excuting queries?
I have a list of .sqls files(50) and I need to list all the tables and respective columns used in all those files.
Getting execution plan would be next thing. But at first searching multiple .sql files and getting the list of table and column names.