SQLite Export Data from Table to CSV File

  Total Views : 796
  Comments : 0
  Keywords : SQLite export database daa to csv or excel file using .output command with examples, SQLite export tables data to csv or excel file with examples

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.

SQLite Export Data to CSV File

In SQLite by using “.output” command we can export data from database tables to csv or excel external files based on our requirement.

Syntax of SQLite Export Command

Following is the syntax of “.output” command to export data from database to csv or excel file.

 

.output (filename)

SQLite Export Data to CSV File Example

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;

sqlite> .quit

If you observe above example to export data from SQLite database to CSV or Excel file we followed few steps those are

 

  1. To insert table column names in CSV or Excel file we used .header on command.
  2. To return the data in CSV format we used .mode CSV.
  3. To send data to csv file we used .output command and SELECT statement to export data from required table.

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.

 

SQLite Export Data from Table to CSV File

 

When we open Employee.csv file that will contain all the records of emp_master table like as shown below.

 

emp_id,first_name,last_name,salary,dept_id

1,Honey,Patel,10100,1

2,Shweta,Jariwala,19300,2

3,Vinay,Jariwala,35100,3

4,Jagruti,Viras,9500,2

5,Shweta,Rana,12000,3

6,Sonal,Menpara,13000,1

7,Yamini,Patel,10000,2

8,Khyati,Shah,50000,3

9,Shwets,Jariwala,19400,2

This is how we can export data from SQLite database to CSV or EXCEL files based on our requirements. 

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User