sqliteHow do I create a SQLite database?
-
Create a new file with the
.db
extension. This will be the SQLite database file. -
Connect to the database using the
sqlite3
command. For example:
sqlite3 mydatabase.db
- Create the tables you need in the database. For example:
CREATE TABLE customers (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
address TEXT
);
- Insert data into the tables. For example:
INSERT INTO customers (name, address) VALUES ('John', '123 Main Street');
- Run queries to retrieve data from the database. For example:
SELECT * FROM customers;
Output example
id name address
1 John 123 Main Street
- Close the connection to the database. For example:
.exit
- You can now use the SQLite database file
mydatabase.db
in your application.
Helpful links
More of Sqlite
- How do I use SQLite transactions?
- How do I install SQLite on Windows?
- How do I show the databases in SQLite?
- How do I use the SQLite sequence feature?
- How do I use different data types in SQLite?
- How do I use the SQLite SUBSTRING function?
- How do I use regular expressions to query a SQLite database?
- How can I use SQLite in a portable way?
- How do I resolve an error "no such column" when using SQLite?
- How can I use SQLite with Python to create a database?
See more codes...