Tags

SQLite Database

SQLite is a serverless embedded database that reads and writes to a file. You can read more about it on their site.

List of Commands

You can see a list of commands with the .help command:

$ echo .help | sqlite3

or from within sqlite3 command line shell:

$ sqlite3
sqlite> .help

Use a SQLite Database

$ sqlite3 /path/to/database_file.db

This will make your instance of sqlite use the database in the .db file. It's also how to "open" the file and start using it in SQLite.

View Schema Structure

$ echo .schema | sqlite3 /path/to/my_sqlite_file.db

Import/Export

$ sqlite3 my_sqlite_file.db
sqlite> .output /path/to/my_outputfile.sql
sqlite> .dump

Note that the syntax of this SQL file will not work for MySQL, but it will be close. Some finding and replacing should put it in the correct format.

In particular, you will need to remove double-quotes in CREATE TABLE statements. If the column names in the create statement have spaces in them, you'll need to surround the name with backticks (`) NOT single-quotes.

Example

SQLite

CREATE TABLE IF NOT EXISTS "Misc"("Part Number" varchar(255),"Part Type" varchar(255),"Value" varchar(255));

MySQL

CREATE TABLE IF NOT EXISTS Misc(`Part Number` varchar(255),`Part Type` varchar(255),Value varchar(255));

-- AdmindoMikeRyan - 05 Mar 2018
Topic revision: r1 - 05 Mar 2018, MichaelRyan
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding CLASSE Wiki? Send feedback