You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SQLite is a serverless, file-based, and lightweight SQL database engine.
SQLite doesn't have the concept of multiple databases like MySQL or PostgreSQL. Instead, each SQLite database is a standalone file.
# Show the current database file's path
sqlite> .database
main: /database/mydatabase.db r/w
# List the main database and any attached databases
sqlite> .databases
main: /database/mydatabase.db r/w
Show Tables
# Show all tables in the current database
sqlite> .tables
Show Schema
# Show the schema of a table
sqlite> .schema <table_name>
Show Settings
# Show the current settings
sqlite> .show
echo: off
eqp: off
explain: auto
headers: off
mode: list
nullvalue: ""
output: stdout
colseparator: "|"
rowseparator: "\n"
stats: off
width:
filename: /database/mydatabase.db
Exit
# Exit the sqlite3 shell
sqlite> .exit
# Or
sqlite> .quit
1. Creating a Table
The CREATE TABLE statement is used to create a new table in the database.
0. SQLite common commands
Show Databases
SQLite is a serverless, file-based, and lightweight SQL database engine.
SQLite doesn't have the concept of multiple databases like MySQL or PostgreSQL. Instead, each SQLite database is a standalone file.
Show Tables
Show Schema
Show Settings
Exit
1. Creating a Table
The
CREATE TABLE
statement is used to create a new table in the database.Example:
2. Inserting Data
The
INSERT INTO
statement is used to insert data into a table.Example:
3. Selecting Data
The
SELECT
statement is used to retrieve data from a table.Example:
To select all columns:
4. Updating Data
The
UPDATE
statement is used to modify existing records in a table.Example:
5. Deleting Data
The
DELETE
statement is used to delete records from a table.Example:
6. Filtering Data
The
WHERE
clause is used to filter records that meet a certain condition.Example:
7. Sorting Data
The
ORDER BY
clause is used to sort the result set by one or more columns.Example:
8. Limiting Results
The
LIMIT
clause is used to limit the number of rows returned by a query.Example:
9. Counting Records
The
COUNT()
function is used to count the number of rows that match a condition.Example:
10. Joining Tables
The
JOIN
clause is used to combine rows from two or more tables, based on a related column between them.Example:
11. Grouping Data
The
GROUP BY
statement groups rows that have the same values into summary rows.Example:
12. Creating an Index
The
CREATE INDEX
statement is used to create an index on a column to speed up queries.Example:
13. Dropping a Table
The
DROP TABLE
statement is used to delete a table and all of its data.Example:
14. Dropping an Index
The
DROP INDEX
statement is used to remove an index.Example:
The text was updated successfully, but these errors were encountered: