SlideShare a Scribd company logo
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
Ad

More Related Content

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

PYTHON_DATABASE_CONNECTIVITY_for_class_12.pptx
PYTHON_DATABASE_CONNECTIVITY_for_class_12.pptxPYTHON_DATABASE_CONNECTIVITY_for_class_12.pptx
PYTHON_DATABASE_CONNECTIVITY_for_class_12.pptx
HistoryScienceWorld
 
Python SQite3 database Tutorial | SQlite Database
Python SQite3 database Tutorial | SQlite DatabasePython SQite3 database Tutorial | SQlite Database
Python SQite3 database Tutorial | SQlite Database
ElangovanTechNotesET
 
Python database access
Python database accessPython database access
Python database access
Smt. Indira Gandhi College of Engineering, Navi Mumbai, Mumbai
 
Sq lite module9
Sq lite module9Sq lite module9
Sq lite module9
Highervista
 
SQL-Connectivity python for beginners easy explanation with concepts and outp...
SQL-Connectivity python for beginners easy explanation with concepts and outp...SQL-Connectivity python for beginners easy explanation with concepts and outp...
SQL-Connectivity python for beginners easy explanation with concepts and outp...
harshitagrawal2608
 
interface with mysql.pptx
interface with mysql.pptxinterface with mysql.pptx
interface with mysql.pptx
KRITIKAOJHA11
 
015. Interface Python with sql interface ppt class 12
015. Interface Python with sql interface ppt class 12015. Interface Python with sql interface ppt class 12
015. Interface Python with sql interface ppt class 12
Shuvanth
 
MySql Interface database in sql python my.pptx
MySql Interface database in sql python my.pptxMySql Interface database in sql python my.pptx
MySql Interface database in sql python my.pptx
UshimArora
 
Interface python with sql database10.pdf
Interface python with sql database10.pdfInterface python with sql database10.pdf
Interface python with sql database10.pdf
HiteshNandi
 
Interface Python with MySQLwedgvwewefwefwe.pptx
Interface Python with MySQLwedgvwewefwefwe.pptxInterface Python with MySQLwedgvwewefwefwe.pptx
Interface Python with MySQLwedgvwewefwefwe.pptx
AyushKumarXIthclass
 
Sq lite
Sq liteSq lite
Sq lite
Revuru Bharadwaja
 
Interfacing python to mysql (11363255151).pptx
Interfacing python to mysql (11363255151).pptxInterfacing python to mysql (11363255151).pptx
Interfacing python to mysql (11363255151).pptx
cavicav231
 
Interface python with sql database.pdf--
Interface python with sql database.pdf--Interface python with sql database.pdf--
Interface python with sql database.pdf--
jagaspeed09
 
Interface python with sql database.pdf
Interface python with sql database.pdfInterface python with sql database.pdf
Interface python with sql database.pdf
MohammadImran709594
 
Database connectivity in python
Database connectivity in pythonDatabase connectivity in python
Database connectivity in python
baabtra.com - No. 1 supplier of quality freshers
 
Mysql python
Mysql pythonMysql python
Mysql python
Janu Jahnavi
 
Mysql python
Mysql pythonMysql python
Mysql python
Janu Jahnavi
 
PythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for DatabasePythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for Database
dharawagh9999
 
AmI 2015 - Databases in Python
AmI 2015 - Databases in PythonAmI 2015 - Databases in Python
AmI 2015 - Databases in Python
Fulvio Corno
 
Interface Python with MySQL.pdf
Interface Python with MySQL.pdfInterface Python with MySQL.pdf
Interface Python with MySQL.pdf
DhirajKumarBiswal
 
PYTHON_DATABASE_CONNECTIVITY_for_class_12.pptx
PYTHON_DATABASE_CONNECTIVITY_for_class_12.pptxPYTHON_DATABASE_CONNECTIVITY_for_class_12.pptx
PYTHON_DATABASE_CONNECTIVITY_for_class_12.pptx
HistoryScienceWorld
 
Python SQite3 database Tutorial | SQlite Database
Python SQite3 database Tutorial | SQlite DatabasePython SQite3 database Tutorial | SQlite Database
Python SQite3 database Tutorial | SQlite Database
ElangovanTechNotesET
 
SQL-Connectivity python for beginners easy explanation with concepts and outp...
SQL-Connectivity python for beginners easy explanation with concepts and outp...SQL-Connectivity python for beginners easy explanation with concepts and outp...
SQL-Connectivity python for beginners easy explanation with concepts and outp...
harshitagrawal2608
 
interface with mysql.pptx
interface with mysql.pptxinterface with mysql.pptx
interface with mysql.pptx
KRITIKAOJHA11
 
015. Interface Python with sql interface ppt class 12
015. Interface Python with sql interface ppt class 12015. Interface Python with sql interface ppt class 12
015. Interface Python with sql interface ppt class 12
Shuvanth
 
MySql Interface database in sql python my.pptx
MySql Interface database in sql python my.pptxMySql Interface database in sql python my.pptx
MySql Interface database in sql python my.pptx
UshimArora
 
Interface python with sql database10.pdf
Interface python with sql database10.pdfInterface python with sql database10.pdf
Interface python with sql database10.pdf
HiteshNandi
 
Interface Python with MySQLwedgvwewefwefwe.pptx
Interface Python with MySQLwedgvwewefwefwe.pptxInterface Python with MySQLwedgvwewefwefwe.pptx
Interface Python with MySQLwedgvwewefwefwe.pptx
AyushKumarXIthclass
 
Interfacing python to mysql (11363255151).pptx
Interfacing python to mysql (11363255151).pptxInterfacing python to mysql (11363255151).pptx
Interfacing python to mysql (11363255151).pptx
cavicav231
 
Interface python with sql database.pdf--
Interface python with sql database.pdf--Interface python with sql database.pdf--
Interface python with sql database.pdf--
jagaspeed09
 
Interface python with sql database.pdf
Interface python with sql database.pdfInterface python with sql database.pdf
Interface python with sql database.pdf
MohammadImran709594
 
PythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for DatabasePythonDatabaseAPI -Presentation for Database
PythonDatabaseAPI -Presentation for Database
dharawagh9999
 
AmI 2015 - Databases in Python
AmI 2015 - Databases in PythonAmI 2015 - Databases in Python
AmI 2015 - Databases in Python
Fulvio Corno
 
Interface Python with MySQL.pdf
Interface Python with MySQL.pdfInterface Python with MySQL.pdf
Interface Python with MySQL.pdf
DhirajKumarBiswal
 

Recently uploaded (20)

Accommodating Neurodiverse Users Online (Global Accessibility Awareness Day 2...
Accommodating Neurodiverse Users Online (Global Accessibility Awareness Day 2...Accommodating Neurodiverse Users Online (Global Accessibility Awareness Day 2...
Accommodating Neurodiverse Users Online (Global Accessibility Awareness Day 2...
User Vision
 
Scientific Large Language Models in Multi-Modal Domains
Scientific Large Language Models in Multi-Modal DomainsScientific Large Language Models in Multi-Modal Domains
Scientific Large Language Models in Multi-Modal Domains
syedanidakhader1
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Building a research repository that works by Clare Cady
Building a research repository that works by Clare CadyBuilding a research repository that works by Clare Cady
Building a research repository that works by Clare Cady
UXPA Boston
 
Cybersecurity Tools and Technologies - Microsoft Certificate
Cybersecurity Tools and Technologies - Microsoft CertificateCybersecurity Tools and Technologies - Microsoft Certificate
Cybersecurity Tools and Technologies - Microsoft Certificate
VICTOR MAESTRE RAMIREZ
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
Right to liberty and security of a person.pdf
Right to liberty and security of a person.pdfRight to liberty and security of a person.pdf
Right to liberty and security of a person.pdf
danielbraico197
 
SQL Database Design For Developers at PhpTek 2025.pptx
SQL Database Design For Developers at PhpTek 2025.pptxSQL Database Design For Developers at PhpTek 2025.pptx
SQL Database Design For Developers at PhpTek 2025.pptx
Scott Keck-Warren
 
Building Connected Agents: An Overview of Google's ADK and A2A Protocol
Building Connected Agents:  An Overview of Google's ADK and A2A ProtocolBuilding Connected Agents:  An Overview of Google's ADK and A2A Protocol
Building Connected Agents: An Overview of Google's ADK and A2A Protocol
Suresh Peiris
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
SOFTTECHHUB
 
UX for Data Engineers and Analysts-Designing User-Friendly Dashboards for Non...
UX for Data Engineers and Analysts-Designing User-Friendly Dashboards for Non...UX for Data Engineers and Analysts-Designing User-Friendly Dashboards for Non...
UX for Data Engineers and Analysts-Designing User-Friendly Dashboards for Non...
UXPA Boston
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Developing Product-Behavior Fit: UX Research in Product Development by Krysta...
Developing Product-Behavior Fit: UX Research in Product Development by Krysta...Developing Product-Behavior Fit: UX Research in Product Development by Krysta...
Developing Product-Behavior Fit: UX Research in Product Development by Krysta...
UXPA Boston
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
HusseinMalikMammadli
 
Who's choice? Making decisions with and about Artificial Intelligence, Keele ...
Who's choice? Making decisions with and about Artificial Intelligence, Keele ...Who's choice? Making decisions with and about Artificial Intelligence, Keele ...
Who's choice? Making decisions with and about Artificial Intelligence, Keele ...
Alan Dix
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
Top 5 Qualities to Look for in Salesforce Partners in 2025
Top 5 Qualities to Look for in Salesforce Partners in 2025Top 5 Qualities to Look for in Salesforce Partners in 2025
Top 5 Qualities to Look for in Salesforce Partners in 2025
Damco Salesforce Services
 
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
UXPA Boston
 
Accommodating Neurodiverse Users Online (Global Accessibility Awareness Day 2...
Accommodating Neurodiverse Users Online (Global Accessibility Awareness Day 2...Accommodating Neurodiverse Users Online (Global Accessibility Awareness Day 2...
Accommodating Neurodiverse Users Online (Global Accessibility Awareness Day 2...
User Vision
 
Scientific Large Language Models in Multi-Modal Domains
Scientific Large Language Models in Multi-Modal DomainsScientific Large Language Models in Multi-Modal Domains
Scientific Large Language Models in Multi-Modal Domains
syedanidakhader1
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Building a research repository that works by Clare Cady
Building a research repository that works by Clare CadyBuilding a research repository that works by Clare Cady
Building a research repository that works by Clare Cady
UXPA Boston
 
Cybersecurity Tools and Technologies - Microsoft Certificate
Cybersecurity Tools and Technologies - Microsoft CertificateCybersecurity Tools and Technologies - Microsoft Certificate
Cybersecurity Tools and Technologies - Microsoft Certificate
VICTOR MAESTRE RAMIREZ
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
Right to liberty and security of a person.pdf
Right to liberty and security of a person.pdfRight to liberty and security of a person.pdf
Right to liberty and security of a person.pdf
danielbraico197
 
SQL Database Design For Developers at PhpTek 2025.pptx
SQL Database Design For Developers at PhpTek 2025.pptxSQL Database Design For Developers at PhpTek 2025.pptx
SQL Database Design For Developers at PhpTek 2025.pptx
Scott Keck-Warren
 
Building Connected Agents: An Overview of Google's ADK and A2A Protocol
Building Connected Agents:  An Overview of Google's ADK and A2A ProtocolBuilding Connected Agents:  An Overview of Google's ADK and A2A Protocol
Building Connected Agents: An Overview of Google's ADK and A2A Protocol
Suresh Peiris
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
OpenAI Just Announced Codex: A cloud engineering agent that excels in handlin...
SOFTTECHHUB
 
UX for Data Engineers and Analysts-Designing User-Friendly Dashboards for Non...
UX for Data Engineers and Analysts-Designing User-Friendly Dashboards for Non...UX for Data Engineers and Analysts-Designing User-Friendly Dashboards for Non...
UX for Data Engineers and Analysts-Designing User-Friendly Dashboards for Non...
UXPA Boston
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Developing Product-Behavior Fit: UX Research in Product Development by Krysta...
Developing Product-Behavior Fit: UX Research in Product Development by Krysta...Developing Product-Behavior Fit: UX Research in Product Development by Krysta...
Developing Product-Behavior Fit: UX Research in Product Development by Krysta...
UXPA Boston
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
Multi-Agent AI Systems: Architectures & Communication (MCP and A2A)
HusseinMalikMammadli
 
Who's choice? Making decisions with and about Artificial Intelligence, Keele ...
Who's choice? Making decisions with and about Artificial Intelligence, Keele ...Who's choice? Making decisions with and about Artificial Intelligence, Keele ...
Who's choice? Making decisions with and about Artificial Intelligence, Keele ...
Alan Dix
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
Top 5 Qualities to Look for in Salesforce Partners in 2025
Top 5 Qualities to Look for in Salesforce Partners in 2025Top 5 Qualities to Look for in Salesforce Partners in 2025
Top 5 Qualities to Look for in Salesforce Partners in 2025
Damco Salesforce Services
 
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
Longitudinal Benchmark: A Real-World UX Case Study in Onboarding by Linda Bor...
UXPA Boston
 
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")
  翻译: