List and Drop Table
π Listing All Tables in a Databaseβ
A database schema contains metadata about all objects in the database, including tables, views, and indexes. If you want to see only the tables in your database, you can query the schema for objects of type table.
Suppose you have a database with the following tables:
- SQL Table
- SQL Code
- Output
Tables in Database
| Table Name |
|--------------|
| past |
| events |
| crew |
SELECT name
FROM sqlite_schema
WHERE type = 'table';
| name |
|---|
| past |
| events |
| crew |
tip
β Tip: Querying the schema is a reliable way to list all tables in your SQLite database.
π― Example: Listing Table Names Onlyβ
To list all tables in your database, you only need the name column from the schema. Use a SELECT statement to retrieve just the table names.
- Sample Data
- SQL Code
| name | entry | attendees |
|---|---|---|
| Pride Party | 10 | 79 |
| Classical Day | 15 | 76 |
| Wine tasting | 8 | 43 |
SELECT name
FROM sqlite_schema
WHERE type = 'table';
To get only the table names, select the
namecolumn fromsqlite_schemawheretypeis'table'.