SQLite facilitates you to export data from SQLite database to CSV file. You can export the whole table or less according to your query.
.once command is used to export data to a CSV file followed by the file path/name where you want to write the file.
SQLite Table to CSV file
Let's see an example which will export all the contents of the STUDENT table to a CSV file:
The STUDENT table has the following data:
.header on: It specifies that headers are enabled. This is optional. If you disable headers, the CSV file simply won't contain any data.
.mode csv: It specifies that CSV mode is enabled.
.once: It specifies that the output to be written to the CSV file and next is the exact location.
After execution of the above code, a CSV file is created on the specified location:
It is having the same data of SQLite STUDENT table.
How to open CSV file automatically:
.system command is used to automatically open the CSV file.
The following command open the CSV file automatically in Windows:
This code may be changed according to operating system: