Here we will learn how to export data from sqlite database tables to CSV or excel external files using .output command in sqlite with examples.
In SQLite, by using “.output” command we can export data from database tables to CSV or excel external files based on our requirement.
Following is the syntax of “.output” command to export data from the database to CSV or excel file.
We will export “emp_master” table data to Employee.csv file for that write the query like as shown below. Let’s look at the example of exporting data of emp_master table to Employee.csv file. This file does not exist. So it will first create and export data into it.
sqlite> .header on
sqlite> .mode csv
sqlite> .output Employee.csv
sqlite> SELECT * FROM emp_master;
If you observe above example to export data from SQLite database to CSV or Excel file we followed few steps those are
Once we execute the above statements Employee.csv file will create in the folder where our SQLite3.exe file exists with emp_master table data like shown following.
When we open the Employee.csv file that will contain all the records of emp_master table like as shown below.
This is how we can export data from SQLite database to CSV or EXCEL files based on our requirements.