SlideShare a Scribd company logo
2
Most read
8
Most read
SQLITE 3 IN PYTHON
SQLITE 3
• SQL is a query language and is very popular in databases.
• Many websites use MySQL. SQLite is a “light” version that works over syntax
very much similar to SQL.
• SQLite is a self-contained, high-reliability, embedded, full-featured, public-
domain, SQL database engine.
• It is the most used database engine on the world wide web.
• Python has a library to access SQLite databases, called sqlite3, intended for
working with this database which has been included with Python package
since version 2.5.
DIFFERENT METHODS IN SQLITE3
• Connect - Connecting to the SQLite Database can be established using
the connect() method, passing the name of the database to be accessed as a
parameter. If that database does not exist, then it’ll be created.
• Cursor - If you want to execute some queries after the connection is being made. For
that, a cursor has to be created using the cursor() method on the connection
instance, which will execute our SQL queries.
• Execute - The SQL query to be executed can be written in form of a string, and then
executed by calling the execute() method on the cursor object. Then, the result can
be fetched from the server by using the fetchall() method, which in this case, is the
SQLite Version Number.
• Close – This method will used to close the connection between the application and
database using close().
CONNECTING, CURSOR, EXECUTE AND CLOSE
STORAGE CLASSES AND DATATYPES IN SQLITE3
CREATE TABLE
CREATE TABLE database_name.table_name(
column1 datatype PRIMARY KEY(one or more
columns),
column2 datatype,
column3 datatype,
…..
columnN datatype
);
Code in Jupyter Notebook
Approach:
• Import the required module
• Establish the connection or create a connection object with the database using the connect()
function of the sqlite3 module.
• Create a Cursor object by calling the cursor() method of the Connection object.
• Form table using the CREATE TABLE statement with the execute() method of the Cursor class.
INSTERTING DATA
• The SQL INSERT INTO statement of SQL is used to insert a new row in a table. There are two ways of
using the INSERT INTO statement for inserting rows:
• Only values: The first method is to specify only the value of data to be inserted without the column
names.
• Column names and values both: In the second method we will specify both the columns which we
want to fill and their corresponding values.
• Syntax for Only Values: INSERT INTO table_name VALUES (value1, value2, value3,…);
• Example : cursor.execute('''INSERT INTO STUDENT VALUES ('Raju', '7th', 'A')''')
• Syntax for Column names & values:
INSERT INTO table_name (column1, column2, column3,..) VALUES ( value1, value2, value3,..);
• Example:
cursor.execute( '''INSERT INTO STUDENT (CLASS, SECTION, NAME) VALUES ('7th', 'A', 'Raju')''')
SELECTING DATA
• This statement is used to retrieve data from an SQLite table and this returns the data
contained in the table.
• In SQLite the syntax of Select Statement is: SELECT * FROM table_name;
Read All Rows:
• This Select statement is used to retrieve data from the table and fetch all records. To fetch all
records we will use fetchall() method.
• Syntax : cursor.fetchall()
Example: output = cursor_obj.fetchall()
Read Some Rows:
• Now we will use the Select statement to retrieve data from the table and fetch many records
not all. To fetch many records we will use fetchmany() method.
Syntax : cursor.fetchmany(size) Example: output = cursor_obj.fetchmany(5)
DELETING DATA
Deleting specific data
• Syntax : DELETE FROM table_name [WHERE Clause]
Approach:
• Import the required module.
• Establish the connection or create a connection object with the database using to connect()
function of the sqlite3 module.
• Create a Cursor object by calling the cursor() method of the Connection object.
• Finally, trigger to execute() method on the cursor object, bypassing a DELETE statement as a
parameter to it.
Example: cursor_obj.execute("DELETE FROM GEEK WHERE Score < 15“)
Deleting All data
Example: cursor_obj.execute("DELETE FROM GEEK")
UPDATING DATA
• The UPDATE statement in SQL is used to update the data of an existing table in the
database. We can update single columns as well as multiple columns using UPDATE
statement as per our requirement.
• Syntax:
UPDATE table_name SET column1 = value1, column2 = value2,… WHERE
condition;
• In the above syntax, the SET statement is used to set new values to the particular
column, and the WHERE clause is used to select the rows for which the columns are
needed to be updated.
• Example:
cursor.execute('''UPDATE EMPLOYEE SET INCOME = 5000 WHERE Age<25;''')
DROP TABLE
• DROP is used to delete the entire database or a table. It deleted both records in the
table along with the table structure.
• Syntax: DROP TABLE TABLE_NAME;
• Example: connection.execute("DROP TABLE customers_address")
SQLite 3 chapter 4 BCA Notes Python NEP syllabus

More Related Content

PPTX
3 PYTHON INTERACTION WITH SQLITE (concept of python)
PPTX
Python SQLite3...
PPTX
Chapter -7.pptx
PPTX
Sqlite3 databases
PPTX
python db connection samples and program
PDF
24. SQL .pdf
PPTX
PYTHON_DATABASE_CONNECTIVITY.pptxPYTHON_DATABASE
3 PYTHON INTERACTION WITH SQLITE (concept of python)
Python SQLite3...
Chapter -7.pptx
Sqlite3 databases
python db connection samples and program
24. SQL .pdf
PYTHON_DATABASE_CONNECTIVITY.pptxPYTHON_DATABASE

Similar to SQLite 3 chapter 4 BCA Notes Python NEP syllabus (20)

PPTX
PYTHON_DATABASE_CONNECTIVITY_for_class_12.pptx
PPTX
Python SQite3 database Tutorial | SQlite Database
PPTX
Pyhton with Mysql to perform CRUD operations.pptx
PDF
Sq lite module9
PPTX
SQL-Connectivity python for beginners easy explanation with concepts and outp...
PPTX
interface with mysql.pptx
PPTX
015. Interface Python with sql interface ppt class 12
PPTX
MySql Interface database in sql python my.pptx
PDF
Interface python with sql database10.pdf
PPTX
Interface Python with MySQLwedgvwewefwefwe.pptx
DOCX
PPTX
Interfacing python to mysql (11363255151).pptx
PDF
Interface python with sql database.pdf--
PDF
Interface python with sql database.pdf
PPTX
Database connectivity in python
PDF
Mysql python
PPTX
Mysql python
PPTX
PythonDatabaseAPI -Presentation for Database
PDF
AmI 2015 - Databases in Python
PYTHON_DATABASE_CONNECTIVITY_for_class_12.pptx
Python SQite3 database Tutorial | SQlite Database
Pyhton with Mysql to perform CRUD operations.pptx
Sq lite module9
SQL-Connectivity python for beginners easy explanation with concepts and outp...
interface with mysql.pptx
015. Interface Python with sql interface ppt class 12
MySql Interface database in sql python my.pptx
Interface python with sql database10.pdf
Interface Python with MySQLwedgvwewefwefwe.pptx
Interfacing python to mysql (11363255151).pptx
Interface python with sql database.pdf--
Interface python with sql database.pdf
Database connectivity in python
Mysql python
Mysql python
PythonDatabaseAPI -Presentation for Database
AmI 2015 - Databases in Python
Ad

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Tartificialntelligence_presentation.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Big Data Technologies - Introduction.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Getting Started with Data Integration: FME Form 101
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
A Presentation on Artificial Intelligence
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
1. Introduction to Computer Programming.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation_ Review paper, used for researhc scholars
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MIND Revenue Release Quarter 2 2025 Press Release
Reach Out and Touch Someone: Haptics and Empathic Computing
Tartificialntelligence_presentation.pptx
MYSQL Presentation for SQL database connectivity
Assigned Numbers - 2025 - Bluetooth® Document
NewMind AI Weekly Chronicles - August'25-Week II
Big Data Technologies - Introduction.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
SOPHOS-XG Firewall Administrator PPT.pptx
Getting Started with Data Integration: FME Form 101
Network Security Unit 5.pdf for BCA BBA.
The Rise and Fall of 3GPP – Time for a Sabbatical?
A Presentation on Artificial Intelligence
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
1. Introduction to Computer Programming.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Ad

SQLite 3 chapter 4 BCA Notes Python NEP syllabus

  • 1. SQLITE 3 IN PYTHON
  • 2. SQLITE 3 • SQL is a query language and is very popular in databases. • Many websites use MySQL. SQLite is a “light” version that works over syntax very much similar to SQL. • SQLite is a self-contained, high-reliability, embedded, full-featured, public- domain, SQL database engine. • It is the most used database engine on the world wide web. • Python has a library to access SQLite databases, called sqlite3, intended for working with this database which has been included with Python package since version 2.5.
  • 3. DIFFERENT METHODS IN SQLITE3 • Connect - Connecting to the SQLite Database can be established using the connect() method, passing the name of the database to be accessed as a parameter. If that database does not exist, then it’ll be created. • Cursor - If you want to execute some queries after the connection is being made. For that, a cursor has to be created using the cursor() method on the connection instance, which will execute our SQL queries. • Execute - The SQL query to be executed can be written in form of a string, and then executed by calling the execute() method on the cursor object. Then, the result can be fetched from the server by using the fetchall() method, which in this case, is the SQLite Version Number. • Close – This method will used to close the connection between the application and database using close().
  • 5. STORAGE CLASSES AND DATATYPES IN SQLITE3
  • 6. CREATE TABLE CREATE TABLE database_name.table_name( column1 datatype PRIMARY KEY(one or more columns), column2 datatype, column3 datatype, ….. columnN datatype ); Code in Jupyter Notebook Approach: • Import the required module • Establish the connection or create a connection object with the database using the connect() function of the sqlite3 module. • Create a Cursor object by calling the cursor() method of the Connection object. • Form table using the CREATE TABLE statement with the execute() method of the Cursor class.
  • 7. INSTERTING DATA • The SQL INSERT INTO statement of SQL is used to insert a new row in a table. There are two ways of using the INSERT INTO statement for inserting rows: • Only values: The first method is to specify only the value of data to be inserted without the column names. • Column names and values both: In the second method we will specify both the columns which we want to fill and their corresponding values. • Syntax for Only Values: INSERT INTO table_name VALUES (value1, value2, value3,…); • Example : cursor.execute('''INSERT INTO STUDENT VALUES ('Raju', '7th', 'A')''') • Syntax for Column names & values: INSERT INTO table_name (column1, column2, column3,..) VALUES ( value1, value2, value3,..); • Example: cursor.execute( '''INSERT INTO STUDENT (CLASS, SECTION, NAME) VALUES ('7th', 'A', 'Raju')''')
  • 8. SELECTING DATA • This statement is used to retrieve data from an SQLite table and this returns the data contained in the table. • In SQLite the syntax of Select Statement is: SELECT * FROM table_name; Read All Rows: • This Select statement is used to retrieve data from the table and fetch all records. To fetch all records we will use fetchall() method. • Syntax : cursor.fetchall() Example: output = cursor_obj.fetchall() Read Some Rows: • Now we will use the Select statement to retrieve data from the table and fetch many records not all. To fetch many records we will use fetchmany() method. Syntax : cursor.fetchmany(size) Example: output = cursor_obj.fetchmany(5)
  • 9. DELETING DATA Deleting specific data • Syntax : DELETE FROM table_name [WHERE Clause] Approach: • Import the required module. • Establish the connection or create a connection object with the database using to connect() function of the sqlite3 module. • Create a Cursor object by calling the cursor() method of the Connection object. • Finally, trigger to execute() method on the cursor object, bypassing a DELETE statement as a parameter to it. Example: cursor_obj.execute("DELETE FROM GEEK WHERE Score < 15“) Deleting All data Example: cursor_obj.execute("DELETE FROM GEEK")
  • 10. UPDATING DATA • The UPDATE statement in SQL is used to update the data of an existing table in the database. We can update single columns as well as multiple columns using UPDATE statement as per our requirement. • Syntax: UPDATE table_name SET column1 = value1, column2 = value2,… WHERE condition; • In the above syntax, the SET statement is used to set new values to the particular column, and the WHERE clause is used to select the rows for which the columns are needed to be updated. • Example: cursor.execute('''UPDATE EMPLOYEE SET INCOME = 5000 WHERE Age<25;''')
  • 11. DROP TABLE • DROP is used to delete the entire database or a table. It deleted both records in the table along with the table structure. • Syntax: DROP TABLE TABLE_NAME; • Example: connection.execute("DROP TABLE customers_address")