Sqlite Batch File Insert
CS145 - Introduction to Databases Bulk-Loading Data into SQLite DatabasesOverviewBulk-loading refers to the process of loading data specifiedin lines of a file directly into a database system, rather thanexecuting a large series of INSERT statements. Wefirst describe the data file format for bulk-loading into SQLitedatabases, then the loading process.
The Data FileThe data file consists of a sequence of lines, each one specifyingone tuple to be loaded into an existing table of the database. Eachline lists values for the attributes of the table, in the order theattributes were declared when the table was created. Any string can beused as the separator between attribute values; by default, it is' '.As an example, suppose we are bulk-loading into a tableStudent(ID,name), where ID is an integer andname is a string. If we specify ' ' as ourseparator, our data file (call it students.dat) might looklike:123 Alice456 Bob789 CarolAs the result of loading file students.dat, the followingtuples are inserted into table Student:(123,'Alice')(456,'Bob')(789,' Carol')Warning: Notice that the third line of students.dathas a blank after separator ' '. This blank is notignored by the loader, i.e., string 'Carol' is loaded with a leadingblank, as demonstrated by the third tuple above.
Sqlite Insert Multiple Rows
SQLite script FAQ: How do I read/execute a CREATE TABLES script from the command line? (How do I read or execute commands in a file from the sqlite3 command line?) BackgroundMany times when you’re working with a SQLite database, you’ll keep all your CREATE TABLE SQL commands in a database script, which you'll then execute from your database server command line prompt. The file of database commands you execute is often referred to as a 'script', or in this case, a 'SQLite script'. How to execute a SQLite script (file)SQLite is no different, and assuming your CREATE TABLE commands are in a file named create.sql, you can execute your script from the SQLite command line using the.read command, like this:sqlite.read create.sqlAs the name of the command implies, this command reads your SQLite script/file and executes all of the command in it.On a related note, if you need an example SQLite script to work with, please see my article.