SQLite | SQLite Commands | Show Column Names in SELECT Results (.headers)

The .headers command controls whether SELECT results display column names. This article explains how to use it.

Using the .headers Command

Use .headers to show or hide column-name headers in query results. The syntax is as follows.

.headers on|off

.headers on shows headers and .headers off hides them. The alias .header is also accepted.

Use .show to inspect the current setting.

.show
sqlite> .show
        echo: off
         eqp: off
     explain: auto
     headers: off
        mode: list
   nullvalue: ""
      output: stdout
colseparator: "|"
rowseparator: "\n"
       stats: off
       width: 
    filename: mydb.sqlite3
sqlite> 

When headers is off, headers are not displayed.

Query the data with the default setting.

select * from user;
sqlite> select * from user;
1|devkuma|Seoul
2|kimkc|Busan
3|araikuma|Seoul
4|happykuma|Seoul
5|mykuma|Daejeon
sqlite> 

Only data is shown. Enable headers and query again.

.headers on
sqlite> .headers on
sqlite> 
sqlite> select * from user;
id|name|address
1|devkuma|Seoul
2|kimkc|Busan
3|araikuma|Seoul
4|happykuma|Seoul
5|mykuma|Daejeon
sqlite> 

The first row now displays column names.

Next, change the output mode to see how headers are formatted.

mode = csv :

sqlite> .mode csv
sqlite> 
sqlite> select * from user;
id,name,address
1,devkuma,Seoul
2,kimkc,Busan
3,araikuma,Seoul
4,happykuma,Seoul
5,mykuma,Daejeon
sqlite> 

mode = column :

sqlite> .mode column
sqlite> 
sqlite> select * from user;
id          name        address   
----------  ----------  ----------
1           devkuma     Seoul     
2           kimkc       Busan     
3           araikuma    Seoul     
4           happykuma   Seoul     
5           mykuma      Daejeon   
sqlite> 

mode = html :

sqlite> select * from user;
<TR><TH>id</TH>
<TH>name</TH>
<TH>address</TH>
</TR>
<TR><TD>1</TD>
<TD>devkuma</TD>
<TD>Seoul</TD>
</TR>
<TR><TD>2</TD>
<TD>kimkc</TD>
<TD>Busan</TD>
</TR>
<TR><TD>3</TD>
<TD>araikuma</TD>
<TD>Seoul</TD>
</TR>
<TR><TD>4</TD>
<TD>happykuma</TD>
<TD>Seoul</TD>
</TR>
<TR><TD>5</TD>
<TD>mykuma</TD>
<TD>Daejeon</TD>
</TR>
sqlite> 

mode = tabs :

sqlite> .mode tabs
sqlite> 
sqlite> select * from user;
id	name	address
1	devkuma	Seoul
2	kimkc	Busan
3	araikuma	Seoul
4	happykuma	Seoul
5	mykuma	Daejeon
sqlite> 

mode = tcl :

sqlite> .mode tcl
sqlite> 
sqlite> select * from user;
"id" "name" "address"
"1" "devkuma" "Seoul"
"2" "kimkc" "Busan"
"3" "araikuma" "Seoul"
"4" "happykuma" "Seoul"
"5" "mykuma" "Daejeon"
sqlite> 

Headers are formatted according to the active output mode.