sqliteHow do I format a SQLite database?
SQLite is a powerful and easy-to-use database engine. To format a SQLite database, you must first define the schema of the database. This is done by creating tables that define the columns and data types of each field.
For example, the following code creates a table named users
with three columns: id
, name
, and age
:
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
age INTEGER NOT NULL
);
Once the table is created, you can insert data into it with the INSERT
statement. For example, the following code inserts a new user into the users
table with an id
of 1, a name
of "John", and an age
of 25:
INSERT INTO users (id, name, age) VALUES (1, 'John', 25);
You can also use the UPDATE
statement to modify existing data in the table. For example, the following code updates the name
of the user with an id
of 1 to "Jane":
UPDATE users SET name = 'Jane' WHERE id = 1;
You can also delete data from the table with the DELETE
statement. For example, the following code deletes the user with an id
of 1:
DELETE FROM users WHERE id = 1;
Finally, you can query the database with the SELECT
statement. For example, the following code selects all users from the users
table:
SELECT * FROM users;
Code Parts Explanation
CREATE TABLE
: Creates a new table in the database with the specified columns and data types.INSERT
: Inserts a new row into the table with the specified values.UPDATE
: Updates an existing row in the table with the specified values.DELETE
: Deletes an existing row in the table.SELECT
: Queries the table and returns the specified data.
Relevant Links
More of Sqlite
- How do I use SQLite transactions?
- How do I use the SQLite sequence feature?
- How do I show the databases in SQLite?
- How can I use SQLite with WebAssembly?
- How do I use SQLite VACUUM to reclaim disk space?
- How can I use a SQLite transaction example?
- How do I use different data types in SQLite?
- How can I use SQLite with Python?
- How can I use Knex.js with SQLite?
- How do I use SQLite keywords to query a database?
See more codes...