PW Akshay


generate functionFri, 02 Dec 2022

Create a student table and insert data. Implement the following SQL commands on the student table: o ALTER table to add new attributes / modify data type / drop attribute o UPDATE table to modify data o ORDER By to display data in ascending / descending order o DELETE to remove tuple(s) o GROUP BY and find the min, max, sum, count and average

import sqlite3 conn = sqlite3.connect('database.db') c = conn.cursor() student_id = "2021" student_name = "chris" student_major = "CSE" c.execute("CREATE TABLE IF NOT EXISTS student (id text, name text, major text)") c.execute("INSERT INTO student (id, name, major) VALUES (?, ?, ?)", (student_id, student_name, student_major)) conn.commit() c.execute("ALTER TABLE student ADD COLUMN gpa REAL") c.execute("UPDATE student SET gpa = 4.0") c.execute("DELETE FROM student WHERE id = ?", (student_id,)) c.execute("SELECT name, major, gpa FROM student ORDER BY major DESC") c.execute("SELECT major, AVG(gpa) FROM student GROUP BY major")

Questions about programming?Chat with your personal AI assistant