List sql tables in pandas.read_sql List sql tables in pandas.read_sql pandas pandas

List sql tables in pandas.read_sql


This answer might be helpful: How do I get list of all tables in a database using TSQL?

Trying changing your SQL string to:

sql = """SELECT * FROM information_schema.tables"""


import pyodbc as dbimport pandas as pdconn = db.connect("DRIVER={SQL Server}; SERVER=YourServerName; PORT=1433; DATABASE=YourDB; UID=User; PWD=Password;")cursor = conn.cursor()cursor.execute('''select * from sys.databases''')df=pd.DataFrame(cursor.fetchall())


With sqllite3 and pandas you can do it by

import sqlite3 import pandas as pd   # create a connection con = sqlite3.connect('database.db') data = pd.read_sql_query('SELECT name from sqlite_master where type= "table";', con)   # show first 5 table namesdata.head()