PW Akshay

Generation

generate functionFri, 02 Dec 2022

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

import sqlite3 connection = sqlite3.connect("database.db") DB_cursor = connection.cursor() DB_cursor.execute("CREATE TABLE students (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, age INTEGER NOT NULL, sex TEXT NOT NULL)" ) DB_cursor.execute("INSERT INTO students (name, age, sex) VALUES ('John', '21', 'M')") DB_cursor.execute("INSERT INTO students (name, age, sex) VALUES ('Mary', '25', 'F')") connection.commit() DB_cursor.execute("SELECT * FROM students") DB_cursor.execute("SELECT name, sex FROM students") DB_cursor.execute("ALTER TABLE students ADD COLUMN school TEXT") DB_cursor.execute("ALTER TABLE students MODIFY age INTEGER") DB_cursor.execute("ALTER TABLE students DROP COLUMN school") DB_cursor.execute("UPDATE

Questions about programming?Chat with your personal AI assistant