#database #sql #sqlite #terminal #tools
To import CSV files into SQLite, you can do this in your terminal:
1sqlite3 mydatabase.db
2SQLite version 3.43.2 2023-10-10 13:08:14
3Enter ".help" for usage hints.
4sqlite> .import --csv mydata.csv table_name
If the table already exists and the field names don't match the header names, you can also skip the first row:
1sqlite3 mydatabase.db
2SQLite version 3.43.2 2023-10-10 13:08:14
3Enter ".help" for usage hints.
4sqlite> .import --csv --skip 1 mydata.csv table_name
Importing the file again overwriting what is already in the table:
1sqlite3 mydatabase.db
2SQLite version 3.43.2 2023-10-10 13:08:14
3Enter ".help" for usage hints.
4sqlite> begin;
5sqlite> delete from table_name;
6sqlite> .import --csv --skip 1 mydata.csv table_name
7sqlite> commit;
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.