How to retrieve the column names of a table in Sqlite database ?

Published: April 27, 2023

Tags: SQL; Sqlite3;

DMCA.com Protection Status

Using the Sqlite3 database, you can get a list of column names by querying the table:

Start Sqlite

To do this, first open your terminal and enter Sqlite3 followed by the name of your database file:

Sqlite3 chinook.db

Then type

pragma table_info(<table_name>)

to show all columns in the specified table. The output will show the name of each column, as well as its data type. As an example:

sqlite> PRAGMA table_info(employees);

returns

0|EmployeeId|INTEGER|1||1
1|LastName|NVARCHAR(20)|1||0
2|FirstName|NVARCHAR(20)|1||0
3|Title|NVARCHAR(30)|0||0
4|ReportsTo|INTEGER|0||0
5|BirthDate|DATETIME|0||0
6|HireDate|DATETIME|0||0
7|Address|NVARCHAR(70)|0||0
8|City|NVARCHAR(40)|0||0
9|State|NVARCHAR(40)|0||0
10|Country|NVARCHAR(40)|0||0
11|PostalCode|NVARCHAR(10)|0||0
12|Phone|NVARCHAR(24)|0||0
13|Fax|NVARCHAR(24)|0||0
14|Email|NVARCHAR(60)|0||0

Exit Sqlite

To do that simply type exit:

sqlite> exit

or

press Control+D.

References

Links Site
SQLite wikipedia.org
sqlite sqlite.org