Created
May 29, 2023 17:43
-
-
Save recrsn/69e82ca01eee5f1b5c84f479691da234 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sqlite3 | |
| # Path to your SQLite file | |
| sqlite_file = 'your_database.sqlite' | |
| # Connect to the SQLite database | |
| conn = sqlite3.connect(sqlite_file) | |
| cursor = conn.cursor() | |
| # Get the table names | |
| cursor.execute("SELECT name FROM sqlite_master WHERE type='table';") | |
| tables = cursor.fetchall() | |
| # Loop through the tables | |
| for table in tables: | |
| table_name = table[0] | |
| print(f"Table: {table_name}") | |
| print("Columns:") | |
| # Get the column names for the current table | |
| cursor.execute(f"PRAGMA table_info({table_name});") | |
| columns = cursor.fetchall() | |
| # Loop through the columns | |
| for column in columns: | |
| column_name = column[1] | |
| print(f"- {column_name}") | |
| print() # Add an empty line between tables | |
| # Close the database connection | |
| conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment