In MySQL, when I run the command SHOW TABLES
I can see all the tables present in a particular database.
What about SQLite? How can I do this?
In MySQL, when I run the command SHOW TABLES
I can see all the tables present in a particular database.
What about SQLite? How can I do this?
If you are using the "interpreter" it can use the .tables
or schema
commands to list the tables or their structures.
If you want to do this in code and want a result that can be used for something in your application, refer to the database data dictionary where you have all tables:
SELECT * FROM sqlite_master WHERE type='table';
WHERE
is required because there you also have indexes. If you want only some data, you can filter, choose the columns, whatever you want, you already know how to use SQL. Just do not try to modify this and other control tables because there are no triggers that process everything that is needed.
If you test that the structure is written as text, it puts the command that was used to create the table. It is not very practical to consult, but the information is there.
If you do a ATTACH
you need to tell what database you are referring to. Example:
ATTACH novoBanco.db AS novo;
SELECT * FROM novo.sqlite_master WHERE type='table';
If you need temporary tables, you need to look at another location: sqlite_temp_master
.
This is in the official FAQ .
One thing that few know is that all internal database control is usually in regular tables with special hardcoded access.
Let's say your db is called MEUDB.
You can run the following command:
SELECT name FROM meudb.sqlite_master WHERE type='table';
List the database tables:
.tables
Show table details:
.schema tablename
Show all records in the table:
SELECT * FROM tablename;
List of all SQLite commands (terminal / prompt):
.help
sqlite3 fffffff.sqlite .tables