DATABASE MANAGEMENT SYSTEM – PRACTICAL
NOTES
1. Create Student Table
CREATE TABLE student (
roll INT PRIMARY KEY,
name VARCHAR(25),
marks INT,
class INT
);
2. Insert Data
INSERT INTO student VALUES (1, 'Ravi', 85, 12);
INSERT INTO student VALUES (2, 'Anu', 90, 12);
INSERT INTO student VALUES (3, 'Kiran', 78, 11);
INSERT INTO student VALUES (4, 'Meena', 92, 12);
3. ALTER TABLE – Add Attribute
ALTER TABLE student ADD age INT;
4. ALTER TABLE – Modify Data Type
ALTER TABLE student MODIFY name VARCHAR(40);
5. ALTER TABLE – Drop Attribute
ALTER TABLE student DROP age;
6. UPDATE Table
UPDATE student SET marks = 95 WHERE roll = 1;
7. ORDER BY Clause
SELECT * FROM student ORDER BY marks ASC;
SELECT * FROM student ORDER BY marks DESC;
8. DELETE Records
DELETE FROM student WHERE marks < 40;
9. Aggregate Functions
SELECT MIN(marks) FROM student;
SELECT MAX(marks) FROM student;
SELECT SUM(marks) FROM student;
SELECT COUNT(*) FROM student;
SELECT AVG(marks) FROM student;
10. GROUP BY Clause
SELECT class, AVG(marks) FROM student GROUP BY class;
11. Python – SQL Integration
import [Link]
db = [Link](
host="localhost",
user="root",
password="root",
database="school"
)
cur = [Link]()
[Link]("SELECT * FROM student")
for row in cur:
print(row)
[Link]()