Sql Flashcards
is a lightweight, serverless, and embedded relational
database management system. It is integrated into Python
through the sqlite3 module, which provides a simple and
efficient way to interact with structured data. The ease of use
and portability of SQLite make it ideal for small to medium-
scale applications, local storage, and prototyping.
SQLite
Establishes a connection to an SQLite database. If the database
file doesn’t exist, it will create a new one
Database Connection — sqlite3.connect
Creates a cursor object used to execute SQL commands.
Cursor Object
connection.cursor()
Executes a single SQL query or command.
cursor.execute()
Executes a query multiple times with different parameters sets.
cursor.executemany()
Executes multiples SQL Statements in a single string.
cursor.executescript()
Retrieves all rows of a query result.
cursor.fetchall()
Retrieves the next row of a query result.
cursor.fetchone()
Retrieves a specified number of rows from a query result.
cursor.fetchmany(size)
Commits the current transaction to the database.
Transactions
connection.commit()
Rolls back any changes madde during the current
transaction.
connection.rollback()
Closes the connection to the database.
Connection Management
connection.close()
Gets or sets the isolation level for transactions..
connection.isolation_level()
Creates an in-memory database that disappears when the
connection is closed.
Connection Management
sqlite3.connect(‘:memory:’)
Base class for all SQLite exeptions.
Error Handling
v/ sqlite3.Error
Creates a new table in the database.
CREATE TABLE
Adds new rows of data to a table.
INSERT INTO
Retrieves data from one or more tables.
SELECT
Modifies existing data in a table.
UPDATE
Removes rows from a table.
DELETE
Deletes a table from the database.
DROP TABLE
Specifies conditions for data retrieval or modification.
WHERE
Sorts retrieved data based on one or more columns.
ORDER BY
Restricts the number of rows returned by a query.
LIMIT
— Inserting data into the table using INSERT INTO.
Create Operation
— Read data into the table using SELECT.
Read Operation
— Update data into the table using UPDATE.
Update Operation
— Delete data into the table using DELETE.
Delete Operation
— Always close the database connection when
done.
Closing the connection