load csv to sqlite

Costas

Administrator
Staff member
download (Precompiled Binaries for Windows > sqlite-tools-win32-x86-?.zip) and run sqlite3.exe

note : use back slash for folders

.separator "\t"
.import D:/test/temp/CSVtest/hw_25000.csv tbl3

the sqlite3.exe will get the first row as column names and will be table field names
then you can use sqlite SQL syntax between the created tables but make sure you always end the statement with semicolon (;)!!

--

otherwise you can create the table by hand

create table tbl3(name, population);
.separator "\t"
.import D:/test/temp/CSVtest/hw_25000.csv tbl3

now when table exists, the first line will imported as row

--

using
.tables
lists the tables created on in-memory dbase.

.schema tbl3
shows the create table for the given table.

.save D:/test/hw.db
saves the in-memory dbase to sqlite file.

--

you can automate the process and skip the in-memory dbase, by writing this to action.txt

.separator "\t"
.import D:/test/temp/CSVtest/hw_25000.csv tbl3

then execute
sqlite3 myDB.db < action.txt

this will CREATE the table on myDB.db, get the first row as column names, import the other rows and exit!

the myDB.db is not required to exists.. If exists will do the action on dbase.

If myDB.db exists and tbl3 table exists, will try only to INSERT..

ref - SQLite CLI
 
Top