9951 explained code solutions for 126 technologies


sqliteHow do I create a SQLite database?


  1. Create a new file with the .db extension. This will be the SQLite database file.

  2. Connect to the database using the sqlite3 command. For example:

sqlite3 mydatabase.db
  1. Create the tables you need in the database. For example:
CREATE TABLE customers (
  id INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  address TEXT
);
  1. Insert data into the tables. For example:
INSERT INTO customers (name, address) VALUES ('John', '123 Main Street');
  1. Run queries to retrieve data from the database. For example:
SELECT * FROM customers;

Output example

id  name    address
1   John    123 Main Street
  1. Close the connection to the database. For example:
.exit
  1. You can now use the SQLite database file mydatabase.db in your application.

Helpful links

Edit this code on GitHub