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 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 is not exist. So it will first created and export data into to 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 above statements Employee.csv file will create in folder where our SQLite3.exe file exists with emp_master table data like as shown following.
When we open 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.