SQLite - Create database

By xngo on June 14, 2019

SQLite provides sqlite3 command to create a new database. Run the following command to create a new database file.

sqlite3 mydatabase.db

It is will create mydatabase.db file in your current directory. After that command ran, it provides you with the sqlite> prompt. From here, you can type in directly your SQL statements. To get out, run .quit(Don't forget the dot before the word quit).

Below are examples of SQL statements to create new table, insert data in table and fetch data from table.

CREATE TABLE images(  id INTEGER PRIMARY KEY AUTOINCREMENT,
                        DATE TEXT,
                        name TEXT,
                        SIZE INTEGER,
                        file BLOB
                    );
 
INSERT INTO images(DATE, name, SIZE) VALUES('2019-01-11', 'logo',   352);
INSERT INTO images(DATE, name, SIZE) VALUES('2018-01-11', 'logo1',  552);
INSERT INTO images(DATE, name, SIZE) VALUES('2015-01-11', 'logo3', 4552);
INSERT INTO images(DATE, name, SIZE) VALUES('2014-01-11', 'logo3', 1552);
 
SELECT * FROM images WHERE DATE >'2014-11-20' AND DATE < '2017-01-01';

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.