2. 2
Certificate
This is to certify that __________________ ,
Roll No. _____ of Class 12th Session 2021-22
has prepared the Practical File as per the
prescribed Practical Syllabus of Computer
Science Code-083, Class-12 AISSCE (CBSE)
under my supervision.
It is the original work done by him/her. His/ her
work is really appreciable.
I wish him/her a very bright success.
__________________
Signature of Teacher.
__________________
Signature of External
6. 6
Practical No-1
Date: 27/12/2021
Problem- Create a database 'csfile' on the database server, show the list of databases and
open it.
Solution :
> create database csfile;
> show databases;
> use csfile;
Command and output ( Screenshot ) :
7. 7
Practical No-2
Date: 27/12/2021
Problem- Create the following table named 'Dept' and 'Emp' with appropriate data type, size
and constraint(s). Show its table structure also.
Solution :
create table dept(deptno int(2) primary key, dname varchar(10),
Location varchar(15));
Table structure:
Command : desc dept;
create table Emp(Empno int(4) primary key, Ename varchar(15) not null,
Job varchar(10), MGR int(4), Hiredate date, Sal double(8,2) check (sal>10000),
Comm double(7,2), Deptno int(2) references Dept(deptno));
8. 8
Practical No-3
Date: 27/12/2021
Problem- insert few records/tuples into the table. Verify the entered records.
Solution :
insert into dept values(10, 'Accounts', 'Delhi');
Note : issued similar commands for other records.
10. 10
Practical No-4
Date: 28/12/2021
Problem- Display all the information of employees whose job is NEITHER Manager nor Clerk.
Solution-
select * from emp where job not in ('Manager', 'Clerk');
11. 11
Practical No-5
Date: 28/12/2021
Problem- Display the details of all the employees whose Hiredate is after December 1991.
(consider the Sql’s standard date format)
Solution:
select * from student where Hiredate>'1991-12-31';
Practical No-6
Date: 28/12/2021
Problem- Display the details of all the employees whose Hiredate is maximum. (consider the Sql’s
standard date format)
Solution:
select * from emp where Hiredate=(select max(hiredate) from emp);
12. 12
Practical No-7
Date: 29/12/2021
Problem- Display all information of Clerk and Manager in descending salary wise.
Solution:
select * from emp where job in('Clerk','Manager') order by sal desc;
OR
select * from emp where job ='Clerk' or job='Manager' order by sal desc;
13. 13
Practical No-8
Date: 29/12/2021
Problem-Display all columns arranged in descending order of Job and within the Job in the ascending
order their Names.
Solution:
select * from emp order by Job desc, Sal;
15. 15
Practical No-10
Date: 10/01/2022
Problem- Display Name and Salary of those Employees whose Salary is in the range 40000 and
100000 ( both are inclusive)
Solution:
select EName, Sal from Emp where Sal between 40000 and 100000;
17. 17
Practical No-12
Date: 11/01/2022
Problem- Display average Salary, highest Salary and total no. of Employees for each
department.
Solution:
Select deptno, avg(Sal), Max(Sal), Count(*), from Emp group by deptno;
Practical No-13
Date: 11/01/2022
Problem- Display total no of Clerk, Manager, Analyst, Salesman and Salesman along with their average
Salary.
Solution:
Select Job, count(*), avg(Sal) from Emp group by Job;
18. 18
Practical No-14
Date: 12/01/2022
Problem- Increase the Salary of 'Clerk' by 5% Sal and verify the updated rows.
Solution:
update Emp set Sal=Sal+(Sal*0.05) where Job = 'Clerk';
19. 19
Practical No-15
Date: 12/01/2022
Problem- Add a new column named Address. ( Take the data type and size yourself) and
verify the table structure.
Solution:
Alter table Emp add address varchar(25);
Practical No-16
Date: 12/01/2022
Problem- Delete the column Address and verify the table structure.
Solution:
Alter table Emp drop column Address;
20. 20
Practical No-17
Date: 13/01/2022
Problem- Display Ename, job, salary and Hiredate of 'Analysts' whose Salary is below 65000
Solution:
Select EName, Job, Salary, Hiredate from Emp where Job='Analyst' and Sal<65000;
Practical No-18
Date: 13/01/2022
Problem- Display unique Jobs.
Solution:
Select distinct Job from Emp;
21. 21
Practical No-19
Date: 13/01/2022
Problem- Display Job and highest Salary of Employee of each type of Job, but only for Clerk
and Manager.
Solution:
Select Job, max(Sal) from Emp group by Job having Job in('Clerk','Manager');
Practical No-20
Date: 14/01/2022
Problem- Display Job and highest Salary of Employee of each type of Job, but only for Clerk,
Manager and Analyst arranged in ascending order of job.
Solution:
Select Job, max(Sal) from Emp group by Job having Job in('Clerk','Manager','Analyst') order
by job;
24. 24
Practical No-22
Date: 14/01/2022
Problem- Write a query to display corresponding information from both the tables using equi-join.
Solution:
Select * from emp, dept where emp.deptno=dept.deptno;
25. 25
Practical No-23
Date: 14/01/2022
Problem- Write a query to display Ename, Job and Salary from Emp and its corresponding Dname
and Location from Dept tables using equi-join.
Solution:
Select Ename, Job, Sal, Dname,Location from emp, dept where emp.deptno=dept.deptno;
26. 26
Practical No-24
Date: 14/01/2022
Problem- Write a query to display corresponding information from both the tables using natural join.
Solution:
Select * from emp natural join dept;
27. 27
Practical No-25
Date: 14/01/2022
Problem- Write a query to display corresponding information from both the tables using natural join.
Solution:
Select * from emp natural join dept order by Ename;
29. 29
Practical No-26 (STACK)
Date: 15/01/2022
Problem : Write a program to show push and pop operation using stack.
Solution:
#stack.py
def push(stack,x): #function to add element at the end of list
stack.append(x)
def pop(stack): #function to remove last element from list
n = len(stack)
if(n<=0):
print("Sorry! Stack empty......")
else:
num=stack.pop()
print(num, "is popped out..")
def display(stack): #function to display stack entry
if len(stack)<=0:
print("Sorry! Stack empty.....")
for i in stack:
print(i,end=" ")
#main program starts from here
x=[]
choice=0
while (choice!=4):
print("n********STACK Menu***********")
print("1. push(INSERTION)")
print("2. pop(DELETION)")
print("3. Display ")
print("4. Exit")
choice = int(input("Enter your choice :"))
if(choice==1):
ans='y'
while ans.upper()=='Y':
value = int(input("Enter a value "))
push(x,value)
ans=input('Push more(y/n):')
if ans.upper()=='N':
34. 34
Practical No-27 (PYTHON CONNECTIVITY)
Date: 16/01/2022
Problem : Write a Program to show MySQL database connectivity in python.
PROGRAM:
import mysql.connector as conn
mydb=conn.connect(host="localhost",user="root",passwd="tiger",database="csfile")
# create new cursor
cur=mydb.cursor()
qry1="select * from emp"
cur.execute(qry1)
data=cur.fetchall()
print(data)
OUTPUT:
35. 35
Practical No-28 (PYTHON CONNECTIVITY)
Date: 17/01/2022
Problem : Write a Program to show how to retrieve records from a database table Emp using
MySQL database connectivity in python.
PROGRAM:
import mysql.connector as conn
try:
mydb=conn.connect(host="localhost",user="root",passwd="tiger",database="csfile")
# create new cursor
cur=mydb.cursor()
qry1="select * from emp"
cur.execute(qry1)
data=cur.fetchall()
print ("EmpNo Emp Name Job MgrNO Hiredate Salary Commission DeptNo")
print("-"*80)
for cols in data:
eno = cols[0]
enm = cols[1]
jb =cols[2]
mg=cols[3]
hdt=cols[4]
sl=cols[5]
com=cols[6]
dpt=cols[7]
print (eno,enm,jb,mg,hdt,sl,com,dpt)
print("-"*80)
except:
print ("Error: unable to fecth data")
mydb.close()
37. 37
Practical No-29 (PYTHON CONNECTIVITY)
Date: 18/01/2022
Problem : Write a Program to show how to add records in a database table Emp using
MySQL database connectivity in python.
PROGRAM:
import mysql.connector as conn
mydb=conn.connect(host="localhost",user="root",passwd="tiger",database="csfile")
# create new cursor
cur=mydb.cursor()
eno=int(input("Enter Employee number : "))
enm=input('Enter Employee Name : ')
jb=input("Enter Job: ")
mg=int(input("Enter Manager No : "))
hdt=input("Enter Hiredate (yyyy-mm-dd) : ")
sl=float(input('Enter Salary : '))
com=float(input('Enter Commission : '))
dpt=int(input("Enter Deptt. No : "))
sql="INSERT INTO emp VALUES ('%d', '%s' ,'%s','%d','%s','%f','%f','%d')" %(eno,enm,
jb,mg,hdt, sl,com, dpt)
try:
cur.execute(sql)
print("One row entered successfully...")
mydb.commit()
except:
mydb.rollback()
mydb.close()
OUTPUT:
38. 38
Practical No-30 (PYTHON CONNECTIVITY)
Date: 19/01/2022
Problem : Write a Program to show how to update a record in a database table Emp using
MySQL database connectivity in python.
PROGRAM:
import mysql.connector as conn
mydb=conn.connect(host="localhost",user="root",passwd="tiger",database="csfile")
# create new cursor
cur=mydb.cursor()
eno=int(input("Enter Employee number : "))
sl=float(input('Enter Salary : '))
sql="update emp set sal=%f where empno=%d" % (sl,eno)
try:
ans=input("Are you sure you want to update the record : ")
if ans=='y' or ans=='Y':
cur.execute(sql)
print("Emp no-",eno," salary updated successfully...")
mydb.commit()
except Exception as e:
print("Error! Perhaps Emp no is incorrect...",e)
mydb.rollback()
mydb.close()
OUTPUT:
39. 39
Practical No-31 (PYTHON CONNECTIVITY)
Date: 20/01/2022
Problem : Write a Program to show how to DELETE a record from a database table Emp using
MySQL database connectivity in python.
PROGRAM:
import mysql.connector as conn
mydb=conn.connect(host="localhost",user="root",passwd="tiger",database="csfile")
# create new cursor
cur=mydb.cursor()
eno=int(input("Enter Employee number : "))
sql="delete from emp where empno=%d" % (eno)
try:
ans=input("Are you sure you want to delete the record : ")
if ans=='y' or ans=='Y':
cur.execute(sql)
print("Emp no-",eno," record deleted successfully...")
mydb.commit()
except Exception as e:
print("Error! Perhaps Emp no is incorrect...",e)
mydb.rollback()
mydb.close()
OUTPUT:
Teacher's Signature:
_____________________