0% found this document useful (0 votes)
7 views2 pages

Database Management System Notes

The document provides practical notes on database management, specifically focusing on SQL commands for creating and managing a 'student' table. It includes instructions for creating the table, inserting and updating data, altering the table structure, and performing queries with aggregate functions. Additionally, it demonstrates how to integrate Python with SQL to retrieve data from the database.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Database Management System Notes

The document provides practical notes on database management, specifically focusing on SQL commands for creating and managing a 'student' table. It includes instructions for creating the table, inserting and updating data, altering the table structure, and performing queries with aggregate functions. Additionally, it demonstrates how to integrate Python with SQL to retrieve data from the database.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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]()

You might also like