Day 2 12 C Ls - 8 - Interface Python With SQL
Day 2 12 C Ls - 8 - Interface Python With SQL
12 C
Day – 2
Structured Query Language
• Structured Query Language
• Interface MySQL with Python.
• Display
• Insert
• Update
• Delete
RECALL
• In your notebook , write the command to connect to MySQL database ‘GRADE12’
from Python. (2 mins)
ACTIVITY – 1
• Create database GRADE12 with table MARKS.
• Insert the first 2 records.
MAIN PROGRAM
DISPLAY RECORDS
➢ Display data in tuple in table format using String formatting
After executing insert or update query we must commit our query using connection object with
commit( ).
Eg: - mydb.commit()
PLACE HOLDER - In Python, Placeholder is a word, characters or a string of characters to hold a temporary place.
The placeholder behaves as a dynamic place holder in such a way that you can pass a particular value for that
placeholder
INSERT RECORD
Method 1 : Using
%s format (string
format)
Method 2 : Using
.format( )
DAY - 3
UPDATE RECORDS
➢ Search by id and update mark
'UPDATE stdetails set marks={} where id={}'.format(newm,idno)
DELETE RECORDS
➢Search by id and delete
'Delete from stdetails where ID = {}'.format(idno)