I need to dump a .sql or .csv file into SQLite (I'm using SQLite3 API). I've only found documentation for importing/loading tables, not entire databases. Right now, when I type:
sqlite3prompt> .import FILENAME TABLE
I get a syntax error, since it's expecting a table and not an entire DB.
Remember that the default delimiter for SQLite is the pipe "|"
http://sqlite.awardspace.info/syntax/sqlitepg01.htm#sqlite010
Import your csv or sql to sqlite with phpLiteAdmin, it is excellent.
This is how you can insert into an identity column:
myfile.txt is a file in C:\code\db\predefined\
data.db is in C:\code\db\
myfile.txt contains strings separated by newline character.
If you want to add more columns, it's easier to separate them using the pipe character, which is the default.
SQLite is extremely flexible as it also allows the SQLite specific dot commands in the SQL syntax, (although they are interpreted by CLI.) This means that you can do things like this.
Create a
sms
table like this:Then two files:
To test the import of the CSV file using the SQL file, run:
In conclusion, this means that you can use the
.import
statement in SQLite SQL, just as you can do in any other RDB, like MySQL withLOAD DATA INFILE
etc. However, this is not recommended.Check out termsql. https://gitorious.org/termsql https://gitorious.org/termsql/pages/Home
It converts text to SQL on the command line. (CSV is just text)
Example:
By default the delimiter is whitespace, so to make it work with CSV that is using commata, you'd do it like this:
alternatively you can do this:
By default it will generate column names "COL0", "COL1", if you want it to use the first row for the columns names you do this:
If you want to set custom column names you do this: