1. 'sqlite3' is available on college's Linux machines, '/usr/remote/anaconda-3.5/bin/sqlite3' 2. Type 'sqlite3' at the Linux prompt to start the sqlite3 interactive session, assuming the above path is in the search path already. 3. Two types of 'commands' are supported by sqlite3, those that operate with database setting and the environment, which we call system commands, and those that are SQL commands to work with database tables, which we call database commands. a. Sqlite3 system commands start with a dot '.' Commonly used sqlite3 system commands include .databases # list names and files of attached databases .dump # dump the current database in an SQL text format .exit # exit sqlite3 environment .headers on|off # using header or not in printing .help # show the list of system commands .import FILE TABLE # import data from FILE into TABLE, FILE can be a csv .mode # choose from csv, column, ..., 'column' makes pretty printing .quit # quit sqlite3 environment .read FILE # execute SQL commands in FILE .separator STRING # specify separator in CSV file, e.g., ',' .show # show the current values for various settings b. Sqlite3 commonly SQL commands select * from ; insert values() into
; create table (); vacuum; # clear the storage used by the "dropped" tables 4. To start sqlite3 with a specified database, type sqlite3 at the Linux prompt e.g., sqlite3 testDB.db will either create a new 'testDB.db' or load the existing 'testDB.db' The revisions to the db file within the sqlite3 prompt will be saved automatically. 5. Python programming API for sqlite3: see sqlite3_db.py for an example, or https://www.tutorialspoint.com/sqlite/sqlite_python.htm for a quick introduction 6. Import from existing CSV files typically result in everything being 'text' To restructure the table and specify primary key, one need to re-create the table and copy the contents from old table to the new one. See details here https://stackoverflow.com/questions/969187/altering-sqlite-column-type-and-adding-pk-constraint 7. Execute a SQL script against a database sqlite3 database.sqlite3 < db.sql https://stackoverflow.com/questions/2049109/how-do-i-import-sql-files-into-sqlite-3 *. Good sources to get help https://www.tutorialspoint.com/sqlite/ https://cs.stanford.edu/people/widom/cs145/sqlite/SQLiteLoad.html https://cs.stanford.edu/people/widom/cs145/sqlite/SQLiteIntro.html