SQLite Import Data from CSV File to Table

  Total Views : 740
  Comments : 0
  Keywords : SQLite import csv file data to database tables using .import command with examples, Import command in sqlite to import data from external files to database tables

Here we will learn how to import data from CSV or Excel external files and insert data into database tables with examples.

SQLite Import CSV File Data to Table

In SQLite we can easily import data from external files like csv, excel to database tables by using “.import” command.

Syntax of SQLite Import Command

Following is the syntax of SQLite “import” command to import data from external files.

 

.import filename table-name

In above syntax the .import command is used to import data from an external file and insert it into the specified table. To import data from CSV file, you must have to execute command .mode CSV before .import command and the table must already exist.

 

Now we will see how to import data from csv file to database table with examples.

SQLite Import Data from CSV to Table

I have “test” CSV file at the location where our sqlite3.exe is exist like as shown following.

 

SQLite Import Data from CSV File from Project Folder

 

The test.csv file contains data like as shown below.

 

1,Shweta

2,Vinay

3,Lax

Now to import data from CSV file first create tabled called “test” in database using following query statement.

 

CREATE TABLE test (id INTEGER PRIMARY KEY, value text);

Once we done with table creation, now we will import test.csv data to test table like as shown below.

 

sqlite> .import test.csv test

If you oserve above example we are importing data from test.csv file to test table. Now, we will check the records of test table using following statement.

 

sqlite> SELECT * FROM test;

 

id          value

----------  ----------

1           Shweta

2           Vinay

3           Lax

This is how we can import SQLite data to csv or excel or other external files based on our requirements. 

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User