SQLite Import

You can import a CSV file into SQLite table by using sqlite3 tool and .import command. This command accepts a file name, and a table name.

Here, file name is the file from where the data is fetched and the table name is the table where the data will be imported into. In the absence of the table, it will create the table automatically according to the data in CSV file.

CSV file to SQLite table

Let's take an example where we import the content of a CSV file to a table that doesn't exist currently. Let's name it "EMPLOYEE". It will create a table based on the data of CSV file.

.mode csv
.import /Users/javatpoint1/Desktop/sqlite/student.csv EMPLOYEE
Note: .mode csv is used before .import to prevent the command-line utility from trying to interpret the input file text as some other format.
Sqlite Import 1

Now check if the table is created:

Sqlite Import 2

You can see that EMPLOYEE table is created. Now check the data in EMPLOYEE table:

.mode column
Sqlite Import 3
Note: .mode column is used before SELECT statement to show the data in tabular form and specifies the columns.
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #