📖 generic · 12th TN - English Medium · COMPUTER SCIENCE · Page 284question

DATA MANIPULATION THROUGH SQL · Part 9

Chapter 4: 6 · COMPUTER SCIENCE

cursor = connection.cursor() print("Displaying the name of the Highest Average") cursor.execute("SELECT sname,max(AVERAGE) FROM student ") result = cursor.fetchall() print(result) print("Displaying the name of the Least Average") cursor.execute("SELECT sname,min(AVERAGE) FROM student ") result = cursor.fetchall() print(result) OUTPUT Displaying the name of the Highest Average [('PRIYA', . )] Displaying the name of the Least Average [('TARUN', . )] Updating A Record . You can even update a record (tuple) in a table through python script.

The following example change the name “Priya” to “Priyanka” in a record in “student table” 12th Computer Chapter - - Example . - # code for update operation import sqlite3 # database name to be passed as parameter conn = sqlite3.connect("Academy.db") # update the student record conn.execute("UPDATE Student SET sname ='Priyanka' where Rollno=' '") conn.commit() print ("Total number of rows updated :", conn. ) cursor = conn.execute("SELECT * FROM Student") for row in cursor: print (row) conn.close() OUTPUT Total number of rows updated : ( , 'Akshay', 'B', 'M', . , ' - - ') ( , 'Aravind', 'A', 'M', .

, ' - - ') ( , 'BASKAR', 'C', 'M', . , ' - - ') ( , 'SAJINI', 'A', 'F', . , ' - - ') ( , 'VARUN', 'B', 'M', . , ' - - ') ( , 'Priyanka', 'A', 'F', .

, ' - - ') ( , 'TARUN', 'D', 'M', . , ' - - ') Remember throughout this chapter student table what we have created is taken as example to explain the SQL queries .Example . . - contain the student table with records Note 12th Computer Chapter - - Data Manipulation Through SQL Deletion Operation .

Similar to Sql command to delete a record, Python also allows to delete a record. The following example delete the content of Rollno from "student table" Example . - # code for delete operation import sqlite3 # database name to be passed as parameter conn = sqlite3.connect("Academy.db") # delete student record from database conn.execute("DELETE from Student where Rollno=' '") conn.commit() print("Total number of rows deleted :", conn. ) cursor =conn.execute("SELECT * FROM Student") for row in cursor: print(row) conn.close() OUTPUT Total number of rows deleted : ( , 'Akshay', 'B', 'M', .

, ' - - ') ( , 'BASKAR', 'C', 'M', . , ' - - ') ( , 'SAJINI', 'A', 'F', . , ' - - ') ( , 'VARUN',

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →