67% found this document useful (3 votes)
11K views

Class 12 CSC Practical File Mysql

1. The document contains the practical record file of a student named S Jayadhityaa for the subject Computer Science. 2. It includes programs and queries implemented on stacks, databases, and Python MySQL connectivity. 3. The programs and queries cover operations on stacks like push, pop, display; creating and manipulating database tables; and performing CRUD operations on a database using a Python menu-driven program.

Uploaded by

S JAY ADHITYAA
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
67% found this document useful (3 votes)
11K views

Class 12 CSC Practical File Mysql

1. The document contains the practical record file of a student named S Jayadhityaa for the subject Computer Science. 2. It includes programs and queries implemented on stacks, databases, and Python MySQL connectivity. 3. The programs and queries cover operations on stacks like push, pop, display; creating and manipulating database tables; and performing CRUD operations on a database using a Python menu-driven program.

Uploaded by

S JAY ADHITYAA
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

DELHI PUBLIC SCHOOL BANGALORE NORTH

2022-2023

COMPUTER SCIENCE
(083)

PRACTICAL RECORD FILE

NAME: S JAYADHITYAA

CLASS: XII SEC C


DELHI PUBLIC SCHOOL BANGALORE
NORTH

CERTIFICATE
This is to certify that of
class XII bearing Board examination Roll No.
has successfully completed practical
record file during the academic year 2022-2021 in partial
fulfillment of Term – II practical examination for the subject
COMPUTER SCIENCE (083) conducted by AISSCE, CBSE

Date:

Internal Examiner Principal Signature

External Examiner
Computational Thinking and Programming – II
(PYTHON)
Data Structures
1) Write a Menu Based Program to implement a stack that holds list of numbers. Take care
of overflow/underflow situations. The Menu should be
1. Push
2. Pop
3. Display entire stack content
4. Display Top Node
5. Exit
2) Write a menu driven python program to implement operations on STACK named L that
stores a list of numbers. Define the required functions as per the specifications given
below
1. def PUSHSTACK (STK, N): where the numeric value N is pushed into the stack. If the
size of the stack is 10 report STACK OVERFLOW situation.
2. def IS_EMPTY (STK): returns True if stack is empty otherwise returns False
3. def POPSTACK (STK): where, the function returns the value deleted from the stack.
4. def SHOWSTACK(STK): displays the contents of the stack
5. def PEEK(STK): displays the topmost element of the stack
Write the required top-level statements and function call statements. Note the POPSTACK,
SHOWSTACK and PEEK functions will invoke IS_EMPTY function to check and report STACK
UNDERFLOW situation.

3) Write a Menu Based Program to implement a stack that holds details of books. Take care
of overflow/underflow situations. The Menu should be
1. Push
2. Pop
3. Display entire stack content
4. Display Top Node
5. Exit
Each node of the Stack will have the following
structure [BOOK_ID, TITLE, AUTHOR,
PRICE]

4) Write the definition of a function POP_PUSH ( LPop, LPush, N) in Python. The function
should Pop out the 1ast N elements of the list LPop and Push them into the list LPush .
For example:
If the contents of the list LPop are [10, 15, 20, 30]
And value of N passed is 2,
then the function should create the list LPush as [ 30, 20
J And the list LPop should now contain [10, 15]
NOTE : If the value of N is more than the number of elements present in LPop, then display the
message "Pop not possible" .
Write the required top-level statements and function call statements and execute the program.
Database Management
MYSQL
Write SQL Queries for the following:
1) Create a Database named INSTITUTE
2) Create a table named FACULTY with the following structure.
Table FACULTY
ATTRIBUTE DATATYPE CONSTRAINT
F_ID Integer PRIMARY KEY
Fname Text data with max length 25 characters NOT NULL
Lname Text data with max length 25 characters NOT NULL
and UNIQUE
HIRE_DATE DATE
SALARY DECIMAL SIZE 7,2 Must be >= 5000

3) Create a table named COURSES with the following structure.


Table COURSES
ATTRIBUTE DATATYPE CONSTRAINT
C_ID Text(10) PRIMARY KEY
F_ID Integer Foreign Key
CNAME TEXT SIZE 40 CHARS DEFAULT VALUE “BASIC COURSE”
FEES DECIMAL SIZE 7,2

4) Insert following data records into FACULTY table and COURSES table.

5) To display all records from FACULTY table


6) To display all records from COURSES table
7) To display all records from FACULTY table whose Hire date is more than 05-oct-2001
8) To display F_ID, Fname, Cname of those faculties who charged more than15000 as fees.
9) Display count of all records from COURSES table grouped by F_ID
10) Display all records FACULTY table order by First Name of the faculty in descending order
11) To increase the fees of Dreamweaver course by 500.
12) Alter COURSES table to change size of CNAME field to varchar(50)
13) Alter FACULTY table to add a new field to Phone Number varchar(15)
14) Display distinct F_ID from COURSES table.
15) Delete records from COURSES table having F_ID as 102
16) Display records from FACULTY table where Last name starts with ‘M’
17) Display today’s date
18) Display total and average fees from COURSES table.
19) Display Faculty names from FACULTY table who handle/teach more than one
Course
20) Display all records from FACULTY table whose phone number is NULL
21) Show the structure of FACULTY table and COURSES table
22) Delete all records from COURSES table
23) Revoke the last delete operation
24) Drop COURSES table.

Python MYSQL Connectivity


1) Write a Menu Based Python database connectivity script that
performs the following operations on the table named PRODUCT in SHOP
Database. Observe the data given and set suitable primary key for the table
and appropriate datatypes for the fields.

Table: PRODUCT
P_ ID ProductName Manufacturer Price
TP01 Talcum Powder LAK 40
FW05 Face Wash ABC 45
BS01 Bath Soap ABC 55
SH06 Shampoo XYZ 120
FW12 Face Wash XYZ

The Menu should be


(1) Add a record
(2) Display All Records
(3) Display records of a particular manufacturer.
(4) Modify the Price of a given P_ID entered by user.
(5) Delete a Record of given ProductName
(6) Exit.
MySQL

Create a Database named INSTITUTE.

> create database INSTITUTE;


Query OK, 1 row affected (0.02 sec)

Create a table named FACULTY with the


following structure.

ATTRIBUTE DATATYPE CONSTRAINT


F_ID Integer PRIMARY KEY
Fname Text data with max length 25 characters NOT NULL
Lname Text data with max length 25 characters NOT NULL
and UNIQUE
HIRE_DATE DATE
SALARY DECIMAL SIZE 7,2 Must be >= 5000

> create table FACULTY(F_ID int primary key,


Fname varchar(25) not null, Lname varchar(25)
unique not null, HIRE_DATE date, SALARY
decimal(7,2) check (SALARY >= 5000));
Query OK, 0 rows affected (0.08 sec)
Create a table named COURSES
ATTRIBUTE DATATYPE CONSTRAINT
C_ID Text(10) PRIMARY KEY
F_ID Integer Foreign Key
CNAME TEXT SIZE 40 CHARS DEFAULT VALUE “BASIC COURSE”
FEES DECIMAL SIZE 7,2
with the following structure.

> create table COURSES(C_ID char(10)primary


key, F_ID int, CNAME varchar(40)default "BASIC
COURSE", FEES decimal(7,2),foreign key(F_ID)
references FACULTY(F_ID));
Query OK, 0 rows affected (0.11 sec)

Insert following data records into FACULTY


table and COURSES table.

Table – FACULTY
> insert into FACULTY value (102, "Amit",
"Mishra","1998-10-12",12000);

> insert into FACULTY value (103, "Nitin",


"Vyas","1994-12-24",8000);

> insert into FACULTY value (104, "Rakshit",


"Soni","2001-5-18",14000);

> insert into FACULTY value (105, "Rashmi",


"Malhotra","2004-9-11",11000);

> insert into FACULTY value (106, "Sulekha",


"Srivastava","2006-6-5",10000);

> insert into FACULTY value (107, "Niranjan",


"Kumar","1996-8-26",16000);

Table – COURSES

> insert into COURSES value ('C21', 102, 'Grid


Computing',40000);

> insert into COURSES value ('C22', 106,


'System Design',16000);

> insert into COURSES value ('C23', 104,


'Computer Security',8000);

> insert into COURSES value ('C24', 106, 'Human


Biology',15000);

> insert into COURSES value ('C25', 102,


'Computer Network',20000);

> insert into COURSES value ('C26', 105,


'Visual Basic',6000);
> insert into COURSES value ('C27', 107,
'DreamWeaver',4000);

To display all records from FACULTY table.

> Select * from faculty;


+------+----------+------------+------------+----------+
| F_ID | Fname | Lname | HIRE_DATE | SALARY |
+------+----------+------------+------------+----------+
| 102 | Amit | Mishra | 1998-10-12 | 12000.00 |
| 103 | Nitin | Vyas | 1994-12-24 | 8000.00 |
| 104 | Rakshit | Soni | 2001-05-18 | 14000.00 |
| 105 | Rashmi | Malhotra | 2004-09-11 | 11000.00 |
| 106 | Sulekha | Srivastava | 2006-06-05 | 10000.00 |
| 107 | Niranjan | Kumar | 1996-08-26 | 16000.00 |
+------+----------+------------+------------+----------+
6 rows in set (0.00 sec)

To display all records from COURSES table.

> Select * from courses;


+------+------+-------------------+----------+
| C_ID | F_ID | CNAME | FEES |
+------+------+-------------------+----------+
| C21 | 102 | Grid Computing | 40000.00 |
| C22 | 106 | System Design | 16000.00 |
| C23 | 104 | Computer Security | 8000.00 |
| C24 | 106 | Human Biology | 15000.00 |
| C25 | 102 | Computer Network | 20000.00 |
| C26 | 105 | Visual Basic | 6000.00 |
| C27 | 107 | DreamWeaver | 4000.00 |
+------+------+-------------------+----------+
7 rows in set (0.00 sec)
To display all records from FACULTY table whose
Hire date is more than 05-oct-2001.

> select * from FACULTY where hire_date >'2001-


10-05';
+------+---------+------------+------------+----------+
| F_ID | Fname | Lname | HIRE_DATE | SALARY |
+------+---------+------------+------------+----------+
| 105 | Rashmi | Malhotra | 2004-09-11 | 11000.00 |
| 106 | Sulekha | Srivastava | 2006-06-05 | 10000.00 |
+------+---------+------------+------------+----------+
2 rows in set (0.02 sec)

To display F_ID, Fname, Cname of those


faculties who charged more than 15000 as fees.

> select F_ID, Fname, Cname from FACULTY


natural join COURSES where FEES > 15000;
+------+---------+------------------+
| F_ID | Fname | Cname |
+------+---------+------------------+
| 102 | Amit | Grid Computing |
| 106 | Sulekha | System Design |
| 102 | Amit | Computer Network |
+------+---------+------------------+
3 rows in set (0.01 sec)
Display count of all records from COURSES table
grouped by F_ID.

> select F_ID, count(*) from COURSES group by


F_ID;
+------+----------+
| F_ID | count(*) |
+------+----------+
| 102 | 2 |
| 104 | 1 |
| 105 | 1 |
| 106 | 2 |
| 107 | 1 |
+------+----------+
5 rows in set (0.02 sec)

Display all records FACULTY table order by


First Name of the faculty in descending order.

> select * from FACULTY order by Fname desc;


+------+----------+------------+------------+----------+
| F_ID | Fname | Lname | HIRE_DATE | SALARY |
+------+----------+------------+------------+----------+
| 106 | Sulekha | Srivastava | 2006-06-05 | 10000.00 |
| 105 | Rashmi | Malhotra | 2004-09-11 | 11000.00 |
| 104 | Rakshit | Soni | 2001-05-18 | 14000.00 |
| 103 | Nitin | Vyas | 1994-12-24 | 8000.00 |
| 107 | Niranjan | Kumar | 1996-08-26 | 16000.00 |
| 102 | Amit | Mishra | 1998-10-12 | 12000.00 |
+------+----------+------------+------------+----------+
6 rows in set (0.00 sec)

To increase the fees of Dreamweaver course by


500.

> update COURSES set FEES = (FEES + 500) where


Cname = 'Dreamweaver';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0
Alter COURSES table to change size of CNAME
field to varchar(50).

> Alter table COURSES modify column Cname


varchar(50);
Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0

Alter FACULTY table to add a new field to Phone


Number varchar(15).

> Alter table FACULTY add column ph_no


varchar(15);
Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0

Display distinct F_ID from COURSES table.

> select distinct(F_ID) from COURSES;


+------+
| F_ID |
+------+
| 102 |
| 104 |
| 105 |
| 106 |
| 107 |
+------+
5 rows in set (0.00 sec)
Delete records from COURSES table having F_ID
as 102.

> delete from COURSES where F_ID = 102;


Query OK, 2 rows affected (0.02 sec)

Display records from FACULTY table where Last


name starts with ‘M’.

> select * from FACULTY where Lname like 'M%';


+------+--------+----------+------------+----------+-------+
| F_ID | Fname | Lname | HIRE_DATE | SALARY | ph_no |
+------+--------+----------+------------+----------+-------+
| 105 | Rashmi | Malhotra | 2004-09-11 | 11000.00 | NULL |
| 102 | Amit | Mishra | 1998-10-12 | 12000.00 | NULL |
+------+--------+----------+------------+----------+-------+
2 rows in set (0.01 sec)

Display today’s date.

> select curdate();


+------------+
| curdate() |
+------------+
| 2022-08-28 |
+------------+
1 row in set (0.01 sec)

Display total and average fees from COURSES


table.

> select sum(FEES), avg(FEES) from COURSES;


+-----------+-------------+
| sum(FEES) | avg(FEES) |
+-----------+-------------+
| 49500.00 | 9900.000000 |
+-----------+-------------+
1 row in set (0.01 sec)

Display Faculty names from FACULTY table who


handle/teach more than one Course.

> select Fname, Lname from faculty natural join


courses group by courses.f_id having count(*) >
1;
+---------+------------+
| Fname | Lname |
+---------+------------+
| Sulekha | Srivastava |
+---------+------------+
1 row in set (0.01 sec)

Display all records from FACULTY table whose


phone number is NULL.

> select * from FACULTY where ph_no is NULL;


+------+----------+------------+------------+----------+-------+
| F_ID | Fname | Lname | HIRE_DATE | SALARY | ph_no |
+------+----------+------------+------------+----------+-------+
| 102 | Amit | Mishra | 1998-10-12 | 12000.00 | NULL |
| 103 | Nitin | Vyas | 1994-12-24 | 8000.00 | NULL |
| 104 | Rakshit | Soni | 2001-05-18 | 14000.00 | NULL |
| 105 | Rashmi | Malhotra | 2004-09-11 | 11000.00 | NULL |
| 106 | Sulekha | Srivastava | 2006-06-05 | 10000.00 | NULL |
| 107 | Niranjan | Kumar | 1996-08-26 | 16000.00 | NULL |
+------+----------+------------+------------+----------+-------+
6 rows in set (0.00 sec)
Show the structure of FACULTY table and COURSES
table.

> desc COURSES;


+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| C_ID | char(10) | NO | PRI | NULL | |
| F_ID | int | YES | MUL | NULL | |
| Cname | varchar(50) | YES | | NULL | |
| FEES | decimal(7,2) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
4 rows in set (0.03 sec)

> desc FACULTY;


+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| F_ID | int | NO | PRI | NULL | |
| Fname | varchar(25) | NO | | NULL | |
| Lname | varchar(25) | NO | UNI | NULL | |
| HIRE_DATE | date | YES | | NULL | |
| SALARY | decimal(7,2) | YES | | NULL | |
| ph_no | varchar(15) | YES | | NULL | |
+-----------+--------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

Delete all records from COURSES table.

> delete from courses;


Query OK, 5 rows affected (0.01 sec)

Revoke the last delete operation.

> rollback;
Query OK, 0 rows affected (0.01 sec)

Drop COURSES table.

> drop table courses;


Query OK, 0 rows affected (0.07 sec)
Python MYSQL Connectivity

1) Write a Menu Based Python database


connectivity script that performs the
following operations on the table
named PRODUCT in SHOP Database.
Observe the data given and set
suitable primary key for the table and
appropriate datatypes for the fields.

Table: PRODUCT
P_ ID ProductName Manufacturer Price
TP01 Talcum Powder LAK 40
FW05 Face Wash ABC 45
BS01 Bath Soap ABC 55
SH06 Shampoo XYZ 120
FW12 Face Wash XYZ

The Menu should be:-


(1) Add a record
(2) Display All Records
(3) Display records of a particular
manufacturer.
(4) Modify the Price of a given P_ID
entered by user.
(5) Delete a Record of given ProductName
(6) Exit.

Source Code:
import mysql.connector as ms

con = ms.connect(host = 'localhost', user =


'root', passwd = 'dpsbn')

cur = con.cursor()

cur.execute("create database shop")


cur.execute("use shop")

cur.execute("create table product(p_id char(4)


primary key, prod_name varchar(200), mfr char(3),
price int)")

#
cur.execute("insert into product
values('TP01','Talcum Powder','LAK',40)")
con.commit()

cur.execute("insert into product


values('FW05','Face Wash','ABC',45)")
con.commit()

cur.execute("insert into product


values('BS01','Bath Soap','ABC',55)")
con.commit()

cur.execute("insert into product


values('SH06','Shampoo','XYZ',120)")
con.commit()

cur.execute("insert into product


values('FW12','Face Wash','XYZ',NULL)")
con.commit()
#

while True:
m = int(input("\nEnter input [(1) - (6)]: "))

if m == 1:
a = input("Enter p_id: ")
b = input("Enter prod_name: ")
c = input("Enter manufacturer: ")
d = int(input("Enter price: "))

cur.execute("insert into product


values('{}','{}','{}',{})".format(a,b,c,d))
con.commit()

print("\nDone!!!\n")
elif m == 2:

cur.execute("select * from product")


data1 = cur.fetchall()

print("\n",data1,"\n")
elif m == 3:

e = input("Enter mfr to display record(s):


")
cur.execute("select * from product where
mfr = '{}'".format(e))
data2 = cur.fetchall()

print("\n",data2,"\n")
elif m == 4:

f = input("Enter p_id: ")


g = int(input("Enter new price: "))

cur.execute("update product set price = {}


where p_id = '{}'".format(g,f))
con.commit()
print("\nDone!!!\n")
elif m == 5:

h = input("Enter prod_name: ")


cur.execute("delete from product where
prod_name = '{}'".format(h))
con.commit()

print("\nDone!!!\n")
elif m == 6:
print("\nYou have exited...")
break
else:
print("\nInvalid Input ... Try Again\n")

con.close()

Output:

Enter input [(1) - (6)]: 2

[('BS01', 'Bath Soap', 'ABC', 55), ('FW05',


'Face Wash', 'ABC', 45), ('FW12', 'Face Wash',
'XYZ', None), ('SH06', 'Shampoo', 'XYZ', 120),
('TP01', 'Talcum Powder', 'LAK', 40)]

Enter input [(1) - (6)]: 3


Enter mfr to display record(s): ABC

[('BS01', 'Bath Soap', 'ABC', 55), ('FW05',


'Face Wash', 'ABC', 45)]
Enter input [(1) - (6)]: 5
Enter prod_name: Bath Soap

Done!!!

Enter input [(1) - (6)]: 1


Enter p_id: AK47
Enter prod_name: Assaultnikov
Enter manufacturer: AKM
Enter price: 47000

Done!!!

Enter input [(1) - (6)]: 4


Enter p_id: FW12
Enter new price: 60

Done!!!

Enter input [(1) - (6)]: 6

You have exited...

You might also like