0% found this document useful (0 votes)
1 views

Grd12_asg4_MySQL_PythonMySQLInterface_2024_25 (1)

The document outlines a Computer Science assignment for Grade 12 students at National Public School, Koramangala, focusing on MySQL and Python-MySQL connectivity. It includes tasks such as creating databases and tables, inserting data, altering schemas, modifying table data, and performing various queries. Additionally, it requires students to write Python scripts for updating and inserting student records, displaying student details, and counting students by gender.

Uploaded by

tanmay
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Grd12_asg4_MySQL_PythonMySQLInterface_2024_25 (1)

The document outlines a Computer Science assignment for Grade 12 students at National Public School, Koramangala, focusing on MySQL and Python-MySQL connectivity. It includes tasks such as creating databases and tables, inserting data, altering schemas, modifying table data, and performing various queries. Additionally, it requires students to write Python scripts for updating and inserting student records, displaying student details, and counting students by gender.

Uploaded by

tanmay
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

National Public School, Koramangala 2024-25

Computer Science Assignment – 4


MySQL , Python-MySQL Connectivity
Grade: 12
Date Given: 10.07.24 Date of Completion : 08.08.24
Write MySQL queries for the following:
I) Create database, tables, insert data:
1. Create database Studentdb.
2. Create tables:
a) Create table StuLibrary with the following attributes:

Column name Data type Constraints


IssueId Integer Primary Key
BookId Varchar(10) Not null
StuId Integer Not null
IssuedDate Date
ReturnDate Date
IssuedBy Varchar(20)
b) Create table Student with the following attributes:

Column name Data type Constraints


StuId Integer Primary Key
Name Varchar(20) Not null
ContactNo Varchar(20)
Gender Varchar(1)
ParentName Varchar(50)
AdmDate Date
ClassSec Varchar(5)
3. Insert data into tables:
a) Insert the following information into StuLibrary:

IssueId BookId StuId IssuedDate ReturnDate IssuedBy


1 B111 701 03.06.2022 15.06.2022 Ms. Aliya
2 M222 754 10.06.2022 Ms. Aparna
3 M333 955 01.07.2022 10.07.2022 Ms. Aliya
4 B444 983 15.06.2022 25.06.2022 Ms. Aparna
b) Insert the following information into Student:
StuId Name ContactNo Gender ParentName AdmDate ClassSec
501 Raghav Jain 080-22001111 M Ms. Anu Jain 10.06.2019 12A
545 Kirti 9824466788 F Mr. Kapur 12.06.2019 10B
701 Rashika Kiran 23678901 F Mr. Kiran R 15.06.2019 12B
754 Rahul Goel 1234567890 M Ms. Radha G 13.07.2020 11A
892 Sahil Jain 044-23456789 M Mr. Vikas Jain 14.07.2020 11B
935 Rohan Saini 9845621333 M Mr. Ranjan S 12.06.2021 12C
955 Anjali 8142333788 F Ms. Parul 01.07.2021 11C
983 Sneha A 09867125364 F Ms. Shruti A 03.07.2021 10A
4. Describe the tables.
II) Alter Schema:
a. Add columns ReturnedLate(type varchar(1) default ‘N’), Fine (type Integer default 0) to the
table StuLibrary
b. Create another table StuNamesS that contains details of students whose name starts with ‘S’.
c. Increase width of attribute Name of table Student to 30 characters.
d. Delete column IssuedBy from the table StuLibrary.
III) Modify table data:
a. Update column ReturnedLate to “Y” for IssueId 3,4 of StuLibrary table .
b. Update Fine for books returned late as per the following rule:
Magazine – BookId starting with M – Rs.10
Book-BookId starting with B – Rs. 15
c. Insert the following record to StuLibrary table:
(5,B111, 892, 16.06.2022, 25.06.2022)
d. Delete record with StuId 983 from Students.
IV) Simple DML:
a. Display Names of students who joined in the year 2019 and 2020. Name the result set
“19-20 Admissions”
b. Display details of books that have not yet been returned.
c. Display details of students with maximum and minimum student ids. (using a single query)
d. Display unique BookIds from StuLibrary.
e. Display student details sorted in ascending order of class and section and within each class
and section , sorted in ascending order of student names.
V) Aggregate with group by, join:
a. Display StuId, Name, BookId, IssuedDate and ReturnDate from the tables Student,
StuLibrary.
b. Display BookId and the no. of times each book has been issued. The output is not to
contain magazines issued by the library.
c. Display total fine amount due to the library.
Python – MYSQL interface

Write 4 separate Python scripts for the following:

1) Accept StuId , ContactNo from the user and update the same in the Student table.

2) Accept details of a new admission and insert the record into the table Student.

3) Accept StuId and display details of the student, along with details of books issued for that
student (using natural join). Display a suitable message if the student record is not found.
(Hint: Use cursor.rowcount to check if record is found).

4) Accept gender from the user and display the number of students of the gender entered by
the user.

*****************************************

You might also like