How import data into SQLite from CSV
SQLite delivers mechanism to import data from another source. One of this source is CSV file.
For import data You launch sqlite3 engine. Open or create new database.
sqlite>.open mydb.db
In my one of last posts I decribed how export data from SQL Server to CSV file:
Export data from SQL Server to CSV file
My file fof data is region.csv
, which contains data from region
table.
First step is to create table for these data.
create table region(id_region int PRIMARY KEY,nazwa_region varchar(100)NOT NULL);
The place for data is ready. Now set mode for type of file.
.mode csv
In last step You may import data. Copy region.csv
file into sqlite installation folder.
.import region.csv region
After .import
command You must write path or only name of file ( it is differ from location of file ) and after name of file – name of table for data.
The using SELECT
query You may see your data in region
table in SQLite.