0% found this document useful (0 votes)
18 views2 pages

Using Sqlite3

Uploaded by

harish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Using Sqlite3

Uploaded by

harish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

To print all tables in an SQLite3 database using Python or the SQLite CLI, here’s

how you can do it:

1. Using SQLite3 Command-Line Interface (CLI):


1. Open the SQLite database in the terminal:
bash
Copy code
sqlite3 database_name.db
2. Run the following SQL command:
sql
Copy code
.tables
o This will list all tables in the database.

2. Using Python:
You can use Python's sqlite3 library to programmatically fetch and print all tables:
python
Copy code
import sqlite3

# Connect to the SQLite database


# Replace 'database_name.db' with your database file
connection = [Link]('database_name.db')

# Create a cursor object to execute SQL commands


cursor = [Link]()

# Query to get all table names


[Link]("SELECT name FROM sqlite_master WHERE type='table';")
# Fetch all results
tables = [Link]()

# Print table names


print("Tables in the database:")
for table in tables:
print(table[0])

# Close the connection


[Link]()

3. Output Example:
For a database with tables users, orders, and products, the output would be:
bash
Copy code
Tables in the database:
users
orders
products
This will dynamically list all the tables in the SQLite database! Let me know if you
need more help.

You might also like