Class 12 Computer Science – MySQL Notes
Chapters 12 to 14 Summary (For Homework dated 1/11/25)
Chapter 12: Table Creation and Data Manipulation Commands
• Database stores data in tables made of rows and columns.
• Commands used: CREATE, INSERT, UPDATE, DELETE, ALTER, DROP.
Command Purpose Example
CREATE TABLE Create a new table CREATE TABLE student (rollno INT, name VARCHAR(20));
INSERT Add new record INSERT INTO student VALUES (1, 'Amit');
UPDATE Modify data UPDATE student SET name='Rahul' WHERE rollno=1;
DELETE Remove record DELETE FROM student WHERE rollno=1;
ALTER TABLE Change structure ALTER TABLE student ADD marks INT;
DROP TABLE Delete table DROP TABLE student;
Chapter 13: Grouping Records and Joins in SQL
• Functions are used for calculations or data manipulation.
• GROUP BY groups rows having the same values; HAVING filters grouped data.
Function Type Example
SUM() Aggregate SELECT SUM(Marks) FROM student;
AVG() Aggregate SELECT AVG(Marks) FROM student;
UPPER() Single Row SELECT UPPER(name) FROM student;
Joins in SQL
Type Description Example
Cartesian Join All possible row combinations SELECT * FROM A, B;
Natural Join Joins on common columns SELECT * FROM student NATURAL JOIN teacher;
Equi Join Join with equality condition SELECT * FROM student, teacher WHERE [Link] = [Link];
Chapter 14: Interface Python with MySQL
Steps to connect Python with MySQL using pymysql:
1. Install module: pip install pymysql
2. Import module: import pymysql
3. Connect to database: con = [Link](host='localhost', user='root', password='',
database='school')
4. Execute queries using [Link]() and save using [Link]().
Task Python Code
Insert Record [Link]('INSERT INTO student VALUES (%s,%s,%s)', (1,'Amit',85))
Update Record [Link]('UPDATE student SET marks=90 WHERE rollno=1')
Commit Changes [Link]()
Summary: MySQL is used for data storage and management. Python can connect to MySQL to
perform queries programmatically.