How to list tables using SQLite3 in Python ?
In this article, we will discuss how to list all the tables in the SQLite database using Python.
1. Creating a connection object using connect() method,
sqliteConnection = sqlite3.connect('SQLite_Retrieving_data.db')
2. Created one SQL query with which we will search a list of all tables which are present inside the sqlite3 database.
sql_query = """SELECT name FROM sqlite_master WHERE type='table';"""
3. Using Connection Object, we are creating a cursor object.
cursor = sqliteConnection.cursor()
4. Using execute() methods, we will execute the above SQL query.
5. Finally, We will print a list of all tables which are present inside the sqlite3 database.
Below is the implementation.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course