CS Practical File 2024-25
CS Practical File 2024-25
COMPUTER SCIENCE
PRACTICAL RECORD FILE
AISSCE-2024-25
SUBMITTED BY:
NAME :………………………………...
Board Roll :….….………………………….
1|Page
CERTIFICATE
Certified that this is a bonafide computer science practical record work
done by Mr./Mis._________________during the year 2024- 2025
Submitted for the practical exam held on_________
at__________________________________
2|Page
INDEX
EXP. TITLE OF EXPERIMENT PAGE DATE Signature
NO. NO.
1 HCF of two Numbers 4 18/04/2024
2 Factorial of a number 5 04/05/2024
3 Fibonacci Series to nth Term 6 13/05/2024
4 Sum of all elements in a list 7 17/06/2024
5 Occurrence of any word in a string 8 24/06/2024
6 Reading file line by line and printing 9 02/07/2024
7 Read Lines of a file and store it in a List 10 19/07/2024
8 Number of names in a Text File 11 22/07/2024
9 Frequency of words in a Text File 12 29/07/2024
10 Copying Text File Contents 13 04/08/2024
11 Display File size and File contents in Upper 15 08/08/2024
12 Store and search Details using Binary file 16 18/08/2024
13 Binary file Updating 18 23/08/2024
14 Store and Search details Using CSV file 20 26/08/2024
15 Simulating Dice using Random module 22 09/09/2024
16 Stack implementation 23 12/09/2024
17 Phishing - common word occurring 26 11/10/2024
18 Facebook using Dictionary 27 21/10/2024
19 Armstrong or Palindrome number 29 01/11/2024
20 Employee Details– Interfacing with MySQL 31 10/11/2024
21 MSQL Commands 36 17/11/2024
;
Experiment No: 1 HCF of two Numbers
3|Page
Aim :
Write an application program using python to find HCF of Two numbers using function concept
Program:
defhcf(x, y):
if x > y:
smaller = y
else:
smaller = x
for i in range(1,smaller + 1):
if((x % i == 0) and (y % i == 0)):
hcf = i
return hcf
# Main Block
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("The H.C.F. of", num1,"and", num2,"is", hcf(num1, num2))
Output :
4|Page
Aim :
Write an application program using python to Find the factorial of a number using function
concept
Program:
def factorial(n):
if n == 1:
return n
else:
f=1
for a in range(1,(n+1)):
f*=a
return f
# Main Block
Output:
Enter a number: 6
The factorial of 6 is 720
5|Page
Aim :
Write an application program using python to print the fibonocci series till given nth term
Program:
deffibo(n):
if n <= 1:
return n
else:
f1=0
f2=1
f=f1+f2
FL=[f1,f2]
while n>0:
FL.append(f)
f1=f2
f2=f
f=f1+f2
n=n-1
return FL
#Main Block
nterms = int(input("Enter a number to limit the fibonocci series:"))
ifnterms<= 0:
print("Plese enter a positive integer")
else:
print("Fibonacci sequence:")
print(fibo(nterms-2))
Output:
Fibonacci sequence:
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377]
Aim :
Write an application program using python to Find the sum of all elements of list
6|Page
Program:
defsum_arr(arr,size):
if (size == 0):
return 0
else:
sum=0
for a in arr:
sum+=a
return sum
# Main Block
n=int(input("Enter the number of elements for list:"))
a=[ ]
for i in range(0,n):
element=int(input("Enter element"+str(i+1)+":"))
a.append(element)
print("The list is:")
print(a)
print("Sum of items in list:",sum_arr(a,n))
Output:
Enter the number of elements for list:5
Enter element1:10
Enter element2:20
Enter element3:30
Enter element4:40
Enter element5:50
The list is:
[10, 20, 30, 40, 50]
Sum of items in list: 150
7|Page
Aim :
Write an application program using python to find the Occurrence of any word in a string
Program:
defcountWord(str1,word):
s = str1.split()
count=0
for w in s:
if w==word:
count+=1
return count
Output:
8|Page
Aim :
Write an application program using python to Appending Lines to the file, reading that file line
by line and printing
Program:
L = ["God \n", "is \n", "Love\n"] # Creation of list with three lines
count = 1
for line in Lines:
print("Line{}: {}".format(count, line.strip())) # Displaying Each Line of file using For Loop
count+=1
Output:
Line1: God
Line2: is
Line3: Love
9|Page
Aim :
Program:
count = 1
lst=[] # creating a list
for line in Lines:
print("Line{}: {}".format(count, line.strip())) # Displaying Each Line of file using For Loop
lst. append(line) # Storing each line in to a List
count+=1
print ("Lines in a file is stored in alist : ")
print(lst) #displaying the list
Output:
Line1: Python
Line2: is a
Line3: Programming Language
Lines in a file is stored in alist :
['Python \n', 'is a \n', 'Programming Language \n']
>>>
10 | P a g e
Aim :
Write an application program using python to count the number of names in a text file (each
name stored in separate lines)
Program:
Output:
Enter total number of names :4
Enter name1:John
Enter name2:Ram
Enter name3:Raheem
Enter name4:Suraj
File Contents
************
John
Ram
Raheem
Suraj
11 | P a g e
Aim:
Write an application program using python, To count the number/ frequency of words in a
Text File
Program:
Output:
Enter line1:hai
Enter line2:how are you
Enter line3:welcome back
Aim:
12 | P a g e
Write an application program using python, to Copying contents of one text file and appending
into another text file
Program:
f = open('file1.txt','r')
print ("\nContents in the First file ")
for word in f.read().split():
print(word, end=' ')
f.close()
s = open('file2.txt', 'r')
print ("\nContents in the Second File ")
for word in s.read().split():
print(word,end=' ')
s.close()
print ("\nContents in the Second File after copying from the First file: ")
s = open('file2.txt', 'r')
for word in s.read().split():
print(word,end=' ')
s.close()
13 | P a g e
Output
First file
***********
Enter total number of Lines :2
Enter Line1:hello
Enter Line2:welcome to SRCS
Second file
***********
Enter total number of Lines :3
Enter Line1:StRaphaels cathedral school
Enter Line2:Senior Secondary school
Enter Line3:CBSEaffliated,
Contents in the Second File after copying from the First file:
St Raphaels cathedral school Senior Secondary school CBSE affliated, hello welcome to SRCS
Experiment No: 11Display File size and File contents in Upper case
14 | P a g e
Aim:
Write an application program using python, to Display File size and File contents in Upper case
Program:
Output:
File Entry
***********
Enter total number of Lines :1
Enter Line1:My best school, SRCS
File size in bytes of a plain file: 19
15 | P a g e
Aim:
Write an application program using python,to create binary file to store Rollno and Name,
Search any Rollno and display name if Rollno found otherwise “Rollno not found”
Program:
import pickle
student=[]
f=open('student.dat','wb')
ans='y'
while ans.lower()=='y':
roll = int(input("Enter Roll Number :"))
name = input("Enter Name :")
student.append([roll,name])
ans=input("Add More ?(Y)")
pickle.dump(student,f)
f.close()
f=open('student.dat','rb')
student=[]
while True:
try:
student = pickle.load(f)
except EOFError:
break
ans='y'
while ans.lower()=='y':
found=False
r = int(input("Enter Roll number to search :"))
for s in student:
if s[0]==r:
print("## Name is :",s[1], " ##")
found=True
break
if not found:
print("####Sorry! Roll number not found ####")
ans=input("Search more ?(Y) :")
f.close()
Output:
16 | P a g e
Enter Roll Number :2
Enter Name :Ram
Add More ?(Y)y
Enter Roll Number :3
Enter Name :Raheem
Add More ?(Y)n
Enter Roll number to search :3
## Name is :Raheem ##
Search more ?(Y) :y
Enter Roll number to search :4
####Sorry! Roll number not found ####
Search more ?(Y) :n
17 | P a g e
Aim:
Write an application program using python, to create binary file to store Rollno, Name and
mark , let user to change the marks entered.
Program:
import pickle
student=[]
f=open('student.dat','wb')
ans='y'
while ans.lower()=='y':
roll = int(input("Enter Roll Number :"))
name = input("Enter Name :")
marks = int(input("Enter Marks :"))
student.append([roll,name,marks])
ans=input("Add More ?(Y)")
pickle.dump(student,f)
f.close()
f=open('student.dat','rb+')
student=[]
while True:
try:
student = pickle.load(f)
except EOFError :
break
ans='y'
while ans.lower()=='y':
found=False
r = int(input("Enter Roll number to update :"))
for s in student:
if s[0]==r:
print("## Name is :",s[1], " ##")
print("## Current Marks is :",s[2]," ##")
m = int(input("Enter new marks :"))
s[2]=m
print("## Record Updated ##")
found=True
break
if not found:
print("####Sorry! Roll number not found ####")
ans=input("Update more ?(Y) :")
f.close()
18 | P a g e
Output:
19 | P a g e
Aim:
Write an application program using python, to create CSV file and store
empno,name,salary and search any empno and display name,salary and if not
foundappropriate message.
Program:
Import csv
with open('myfile.csv',mode='a') as csvfile:
mywriter = csv.writer(csvfile,delimiter=',')
ans='y'
while ans.lower()=='y':
eno=int(input("Enter Employee Number "))
name=input("Enter Employee Name ")
salary=int(input("Enter Employee Salary :"))
mywriter.writerow([eno,name,salary])
print("## Data Saved... ##")
ans=input("Add More ?")
Output:
20 | P a g e
Add More ?y
Enter Employee Number 2
Enter Employee Name Riyas
Enter Employee Salary :30000
## Data Saved... ##
Add More ?n
Enter Employee Number to search :2
NAME: Riyas
SALARY : 30000
Search More ? (Y) n
21 | P a g e
Aim:
Write an application program using python, to generate random number 1-6, simulating a
dice
Program:
import random
import time
print("Press CTRL+C to stop the dice ")
play='y'
while play=='y':
try:
while True:
for i in range(10):
print(i)
n = random.randint(1,6)
print(n,end='')
time.sleep(.10)
except KeyboardInterrupt:
print("Your Number is :",n)
ans=input("Play More? (Y) :")
if ans.lower()!='y':
play='n'
break
22 | P a g e
Aim:
Program:
def isEmpty(S):
if len(S)==0:
return True
else:
return False
def Push(S,item):
S.append(item)
top=len(S)-1
def Pop(S):
if isEmpty(S):
return "Underflow"
else:
val = S.pop()
if len(S)==0:
top=None
else:
top=len(S)-1
return val
def Show(S):
if isEmpty(S):
print("Sorry No items in Stack ")
else:
t = len(S)-1
print("(Top)",end=' ')
while(t>=0):
print(S[t],"<==",end=' ')
t-=1
print()
23 | P a g e
val = int(input("Enter Item to Push :"))
Push(S,val)
elif ch==2:
val = Pop(S)
if val=="Underflow":
print("Stack is Empty")
else:
print("\nDeleted Item was :",val)
elifch==3:
Show(S)
elif ch==0:
print("Bye")
break
Output:
24 | P a g e
Enter your choice :0 Bye
25 | P a g e
Experiment No: 17 Phishing - common word occurring
Aim:
Write an application program totake 10 sample phishing email, and find the most common word
occurring using List
Program:
phishingemail=[
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]"
]
myd={}
for e in phishingemail:
x=e.split('@')
for w in x:
if w not in myd:
myd[w]=1
else:
myd[w]+=1
key_max = max(myd,key=myd.get)
print("Most Common Occurring word is :",key_max)
Output:
26 | P a g e
Experiment No: 18 Facebook using Dictionary
Aim:
Write an application program to create profile of users using dictionary, also let the users to
search, delete and update their profile like face book application
Program:
FB={}
n=int(input(" enter no of details to be need "))
for i in range(n):
print (" FB NO ", i+1)
id=int(input(" enter id "))
na=input(" enter the name ")
pl=input(" enter ur place ")
nk=input(" enter profile name ")
r=[na,pl,nk]
FB[id]=r
k=FB.keys()
while True:
c=input(" \n please enter: 'S' for search : 'D' for delete : 'U' for update : ")
if(c in 'Ss'):
se=input(" enter the searching name ")
for i in k:
x=FB[i]
if(x[0]==se):
print (" searching record is : NAME : ",x[0]," , PLACE : ", x[1] ,"
,PROFILE NAME : ", x[2])
elif(c in 'dD'):
x=int(input(" enter id "))
if (x in k):
print(" deleted record is ", FB[x])
del FB[x]
else:
print ("invalid id")
elif(c in 'Uu'):
x=int(input (" enter the id "))
if(x in k):
v=FB[x]
na=v[0]
upl=input(" enter place ")
unk=input(" enter profile name")
FB[x]=[na,upl,unk]
print(" updated record is " ,FB[x])
else:
print(" invalid id")
ch=input(" Do you want to continue y/n")
if(ch!='y'):
27 | P a g e
break
Output:
please enter: 'S' for search : 'D' for delete : 'U' for update : s
enter the searching name sree
searching record is : NAME : sree , PLACE : pkd ,PROFILE NAME : sri
Do you want to continue y/ny
please enter: 'S' for search : 'D' for delete : 'U' for update : u
enter the id 1
enter place thr
enter profile namesreeja
updated record is ['sree', 'thr', 'sreeja']
Do you want to continue y/ny
please enter: 'S' for search : 'D' for delete : 'U' for update : d
enter id 2
invalid id
Do you want to continue y/n
28 | P a g e
Experiment No: 19 Armstrong or Palindrome number
Aim:
Write an application program to,Check whether a number is (i) palindrome (ii) Armstrong by
function with return multiple values
Program:
defcalc(n):
s=0
r=0
while n>0:
d=n%10
r=r*10 + d
s=s+d*d*d
n//=10
return s, r
#main
Output:
enter a number 1
ARMSTRONG & PALINDROME
PALINDROME
29 | P a g e
Experiment No: 20.a Data Insertion – Python with MySQL
Aim:
Write an application program to interface python with SQL database for employees data
insertion.
Program:
import mysql.connector as m
def insertion():
try:
con=m.connect(host='localhost',user='root',password='123',database='sample')
if(con.is_connected()):
print('Successfully connected')
mycur=con.cursor()
empid=int(input("Enter Employee ID :"))
empname= input("Enter employee name :")
query="insert into employee values ({},'{}')".format(empid,empname)
mycur.execute(query)
con.commit()
print ("Record inserted successfully")
mycur.close();
con.close()
except Exception as e:
print(e)
#Main block
insertion()
Output
Successfully connected
Enter Employee ID : 101
Enter employee name :Arjun
Record inserted successfully
30 | P a g e
Experiment No: 20.b Data Deletion – Python with MySQL
Aim:
Write an application program to interface python with SQL database for employees data
deletion.
Program:
import mysql.connector as m
def deletion():
try:
con=m.connect(host='localhost',user='root',password='123',database='sample')
if(con.is_connected()):
print('successfully connected')
mycur=con.cursor()
empid=int(input("Enter Employee ID to be deleted :"))
query="delete from employee where empid={}".format(empid)
mycur.execute(query)
con.commit()
print ("Record deleted successfully")
mycur.close();
con.close()
except Exception as e:
print(e)
#Main Block
deletion()
Output
Successfully connected
Enter Employee ID to be deleted : 101
31 | P a g e
Experiment No: 20.c Data Updating – Python with MySQL
Aim:
Write an application program to interface python with SQL database for employees data
updation.
Program:
import mysql.connector as m
def updation():
try:
con=m.connect(host='localhost',user='root',password='123',database='sample')
if(con.is_connected()):
print('successfully connected')
mycur=con.cursor()
empid=int(input("Enter Employee ID to be update :"))
empname= input("Enter new name of employee :")
query="update employee set name ='{}' where empid={}".format(empname,empid)
mycur.execute(query)
con.commit()
print ("Record updated successfully")
mycur.close();
con.close()
except Exception as e:
print(e)
#Main Block
updation()
Output:
Successfully connected
Enter Employee ID to be update : 101
Enter new name of employee :Arjun Ravi
Record updated successfully
32 | P a g e
Aim:
Write an application program to interface python with SQL database for employees data
display.
Program:
import mysql.connector as m
def display():
try:
con=m.connect(host='localhost',user='root',password='123',database='sample')
if(con.is_connected()):
print('successfully connected')
mycur=con.cursor()
query="Select * from Employee"
mycur.execute(query)
myrows=mycur.fetchall()
print ("Records in Employee table are:")
for row in myrows:
print(row)
print("all rows printed successfully!")
mycur.close();
con.close()
except Exception as e:
print(e)
#Main block
display()
Output:
successfully connected
Records in Employee table are:
[101,’Anu’]
[102,’Minnu’]
[103,’Jinu’]
all rows printed successfully!
33 | P a g e
Aim:
Write an application program to interface python with SQL database for employees data
searching by applying a condition (maximum salary of a teacher).
Program:
import mysql.connector as m
def display():
try:
con=m.connect(host='localhost',user='root',password='123',database='sample')
if(con.is_connected()):
print('successfully connected')
mycur=con.cursor()
query="Select max(sal) from salary; "
mycur.execute(query)
myrow=mycur.fetchall()
print ("Maximum salary of teacher :")
print(myrow)
mycur.close();
con.close()
except Exception as e:
print(e)
#Main block
display()
Output:
successfully connected
Maximum salary of teacher : 59000
34 | P a g e
Experiment NO: 21 MY SQL
1. CREATE DATABASE
AIM
Create a Database of name EMPLOYEE.
QUERY
2. OPEN COMMAND
AIM
Open the Database using the USE command.
QUERY
USE DATA
3. CREATE TABLE
AIM
Create table EMP with specified number of rows and columns and apply necessary constraints.
QUERY
CREATE TABLE EMP
(ENO INTEGER PRIMARYKEY, ENAME VARCHAR (20) UNIQUE,
JOB VARCHAR (20) DEFAULT “CLERK”, GENDER CHAR (1) NOT
NULL, HIRE DATE, SAL FLOAT (6,2) CHECK SAL>2000,COMM INTEGER);
4. INSERT COMMAND
AIM
Insert tuples to the table EMP.
QUERY
INSERT INTO EMP VALUES(1,’KING’,’MANAGER’,’M’,’1981-11-17’,5000,NULL);
INSERT INTO EMP VALUES(2,’BLAKE’,’MANAGER’,’M’,’1981-05-01’,2850,NULL);
35 | P a g e
INSERT INTO EMP VALUES(3,’JASMIN’,’SALESMAN’,’F’,’1982-12-09’,2450,300);
INSERT INTO EMP VALUES(4,’JONES’,’SALESMAN’,’M’,’1983-01-12’,2975,500);
INSERT INTO EMP VALUES(5,’CLARK’,’ANALYST’,’M’,’1983-01-23’,1250,NULL);
INSERT INTO EMP VALUES(6,’GEETHA’,’CLERK’,’F’,’1981-02-22’,1600,NULL);
5. SELECT COMMAND
AIM
Display all employee details.
QUERY
SELECT * FROM EMP;
OUTPUT
AIM
Display ENO, ENAME and JOB of all Employees.
QUERY
SELECT ENO,ENAME,JOB FROM EMP;
OUTPUT
36 | P a g e
Display job of employee by eliminating redundant data.
QUERY
SELECT DISTINCT JOB FROM EMP;
OUTPUT
DISTINCT JOB
MANAGER
SALESMAN
ANALYST
CLERK
OUTPUT
QUERY
SELECT * FROM EMP WHERE ENAME<>’KING’;
OUTPUT
37 | P a g e
5 CLARK ANALYST M 1983-01-23 1250.00 NULL
6 GEETHA CLERK F 1981-02-22 1600.00 NULL
AIM
Display the details of employee ENO,ENAME,SAL of people whose salary is above 2500.
QUERY
SELECT ENO,ENAME,SAL FROM EMP WHERE SAL>2500;
OUTPUT
QUERY
SELECT * FROM EMP WHERE JOB=’MANAGER’ OR GENDER=’M’;
OUTPUT
AIM
Display the ENO, ENAME and COMM of employees with commission.
QUERY
SELECT ENO,ENAME,COMM FROM EMP WHERE COMM IS NOT NULL;
OUTPUT
38 | P a g e
ENO ENAME SAL JOB
3 JASMIN 2450.00 SALESMAN
4 JONES 2975.00 SALESMAN
AIM
Display the details of employees whose job is not salesman.
QUERY
SELECT * FROM EMP WHERE JOB NOT=’SALESMAN’;
OUTPUT
AIM
Display the details of employees whose salary is not between 2000 and 5000.
QUERY
SELECT * FROM EMP WHERE SAL NOT BETWEEN 2000 AND 5000;
39 | P a g e
OUTPUT
QUERY
SELECT * FROM EMP WHERE JOB IN(‘MANAGER’,’SALESMAN’,’CLERK’);
OUTPUT
AIM
To display the details of employees except people having job as Salesman, Manager and Clerk.
QUERY
SELECT * FROM EMP WHERE JOB NOT IN(‘MANAGER’,’SALESMAN’,’CLERK’);
OUTPUT
40 | P a g e
3 JASMIN SALESMAN F 1982-12-09 2450.00 300
4 JONES SALESMAN M 1983-01-12 2975.00 500
AIM
Display the details of Employees whose ENAME ends with ‘S’;
QUERY
SELECT * FROM EMP WHERE ENAME LIKE ‘%S’;
OUTPUT
AIM
Display the details of Employee whose job contains “AL” string.
QUERY
SELECT * FROM EMP WHERE JOB LIKE “%AL%”;
OUTPUT
41 | P a g e
QUERY
SELECT * FROM EMP WHOSE ENAME LIKE “------%”;
OUTPUT
QUERY
SELECT ENO,ENAME,COMM FROM EMP WHERE COMM IS NULL;
OUTPUT
AIM
Display the ENO,ENAME and COMM of employees with commission.
QUERY
SELECT ENO,ENAME,COMM FROM EMP WHERE COMM IS NOT NULL;
OUTPUT
42 | P a g e
OUTPUT
QUERY
SELECT * FROM EMP ORDER BY ENAME DESC;
OUTPUT
43 | P a g e
QUERY
SELECT 5*6 FROM DUAL;
OUTPUT
5*6
30
SYSDATE()
2015-07-19 11:45:30
AIM
Display the current system date.
QUERY
SELECT CURDATE();
OUTPUT
CURDATE()
AIM
Display current date and time.
QUERY
SELECT NOW();
OUTPUT
NOW()
44 | P a g e
AGGREGATE FUNCTIONS
17. SUM FUNCTIONS
AIM
Display the sum of salary of employees having job as Manager.
QUERY
SELECT SUM(SAL) FROM EMP WHERE JOB=’MANAGER’;
OUTPUT
SUM(SAL)
7850.00
18. GROUP BY
AIM
Display the total salary of Employees in each Department
QUERY
SELECT JOB<SUM(SAL) FROM EMP GROUP BY JOB;
OUTPUT
JOB SUM(SAL)
ANALYST 1250.00
CLERK 1600.00
MANAGER 7850.00
SALESMAN 5245.00
AIM
Display the total Salary of Female.
QUERY
SELECT GENDER<SUM(SAL) FROM EMP GROUP BY GENDER
45 | P a g e
GENDER SUM(SAL)
F 4050.00
M 12075.00
QUERY
SELECT JOB<SUM(SAL) FROM EMP GROUP BY JOB HAVING COUNT(*)>=2;
OUTPUT
JOB SUM(SAL)
MANAGER 7850.00
SALESMAN 5425.00
AIM
Display Eno,Ename,Job and increase salary by 1000 whose job is Salesman.
QUERY
SELECT ENO,ENAME,JOB,SAL+1000 FROM EMP WHERE JOB=’SALESMAN’;
OUTPUT
ENO ENAME JOB SAL+1000
3 JASMIN SALESMAN 3450.00
4 JONES SALESMAN 3975.00
QUERY
SELECT ENO.ENAME,JOB,SAL*100,”$” FROM EMP;
46 | P a g e
OUTPUT
ENO ENAME JOB SAL*100 $
1 KING MANAGER 500000 $
2 BLAKE MANAGER 285000 $
3 JASMIN SALESMAN 245000 $
4 JONES SALESMAN 297500 $
5 CLARK ANALYST 125000 $
6 GEETHA CLER 160000 $
QUERY
CREATE TABLE SALARY1 AS(SELECT ENO,ENAME,SAL FROM EMP WHERE
COMM IS NULL);
SELECT * FROM SALARY1;
OUTPUT
ENO ENAME SAL
1 KING 5000
2 BLAKE 2850
5 CLARK 1250
6 GEETHA 1600
22.UPDATE COMMAND
AIM
Update the salary of an employee from EMP table.
QUERY
UPDATE EMP SET SAL=2000 WHERE ENO=2;
SELECT * FROM EMP;
OUTPUT
ENO ENAME JOB GENDER HIRE SAL COMM
1 KING MANAGER M 1981-11-17 5000 NULL
2 BLAKE MANAGER M 1981-03-01 2850 NULL
3 JASMIN SALESMAN F 1982-12-09 2450 300
47 | P a g e
4 JONES SALESMAN M 1983-01-12 2975 300
5 CLARK ANALYST M 1983-01-23 1250 NULL
6 GEETHA CLERK F 1981-02-22 1600 NULL
AIM
Display the table Salary1 after Updating the Salary as 2000 whoseEno is 2.
QUERY
UPDATE SALARY1 SET SAL=2000 WHERE ENO=2;
SELECT * FROM SALARY1;
OUTPUT
ENO ENAME SAL
1 KING 5000
2 BLAKE 2000
5 CLARK 1250
6 GEETHA 1600
AIM
Update the salary as 200 and Comm as 200 whoseEno is 1 and Display it.
QUERY
UPDATE EMP SET VAL=2000,COMM=200 WHERE ENO=1;
SELECT * FROM EMP;
OUTPUT
ENO ENAME JOB GENDER HIRE SAL COMM
1 KING MANAGER M 1981-11-17 5000 200
2 BLAKE MANAGER M 1981-03-01 2000 NULL
3 JASMIN SALESMAN F 1982-12-09 2450 300
4 JONES SALESMAN M 1983-01-12 2975 300
5 CLARK ANALYST M 1983-01-23 1250 NULL
6 GEETHA CLERK F 1981-02-22 1600 NULL
48 | P a g e
QUERY
UPDATE EMP SET SAL=SAL+1000 WHERE JOB=’SALESMAN’;
SELECT * EMP;
OUTPUT
ENO ENAME JOB GENDER HIRE SAL COMM
1 KING MANAGER M 1981-11-17 2000 200
2 BLAKE MANAGER M 1981-03-01 2000 NULL
3 JASMIN SALESMAN F 1982-12-09 3450 300
4 JONES SALESMAN M 1983-01-12 3975 300
5 CLARK ANALYST M 1983-01-23 1250 NULL
6 GEETHA CLERK F 1981-02-22 1600 NULL
QUERY
UPDATE EMP SET SAL=NULL WHERE JOB=’CLERK’;
SELECT * FROM EMP;
OUTPUT
ENO ENAME JOB GENDER HIRE SAL COMM
1 KING MANAGER M 1981-11-17 2000 200
2 BLAKE MANAGER M 1981-03-01 2000 NULL
3 JASMIN SALESMAN F 1982-12-09 3450 300
4 JONES SALESMAN M 1983-01-12 3975 300
5 CLARK ANALYST M 1983-01-23 1250 NULL
6 GEETHA CLERK F 1981-02-22 NULL NULL
25.DELETE COMMAND
AIM
Remove the details of Employee whose Salary is above 3000 and Display it.
49 | P a g e
QUERY
DELET FROM SALARY1 WHERE SAL>3000;
SELECT * FROM SALARY1;
OUTPUT
ENO ENAME JOB GENDER HIRE SAL COMM
2 BLAKE MANAGER M 1981-03-01 2000 NULL
5 CLARK ANALYST M 1983-01-23 1250 NULL
6 GEETHA CLERK F 1981-02-22 NULL NULL
26.VIEW COMMAND
AIM
Create a table COMM1 containing EMPNO,EMPNAME,EJOB,SALARY,HIRE,GEN,COMM and
COMM is NULL and display it.
QUERY
CREATE VIEW COMM1(EMPNO,EMPNAME,EJOB,GEN,HIRE,SALARY,COM)
AS SELECT * FROM EMP WHERE COMM IS NULL;
SELECT * FROM COMM1;
OUTPUT
ENO ENAME JOB GENDER HIRE SAL COMM
2 BLAKE MANAGER M 1981-03-01 2000 NULL
5 CLARK ANALYST M 1983-01-23 1250 NULL
6 GEETHA CLERK F 1981-02-22 NULL NULL
AIM
Create the sample to display the detail of employee like EMPNO,EMPNAME,SALARY and whose
COMM is NULL and Display it.
QUERY
50 | P a g e
ENO ENAME SAL
2 BLAKE 2000
5 CLARK 1250
6 GEETHA NULL
27.BUILT-IN FUNCTIONS
AIM
Convert the given string into Lower Case.
QUERY
OUTPUT
LOWER(“HELLO”)
Hello
AIM
Convert the given string into Upper case.
QUERY
OUTPUT
LOWER(“HELLO”)
HELLO
AIM
Display the sub string of the given string.
QUERY
51 | P a g e
SELECT SUBSTR(“POINTER”,3,2) FROM DUAL;
OUTPUT
SUBSTR(“POINTER”,3,2)
IN
28.DDL COMMANDS
ALTER COMMAND
AIM
Remove column Salary from salary table and display the table
QUERY
ALTER TABLE SALARY1 DROP COLUMN SAL;
SELECT * FROM SALARY1;
OUTPUT
ENO ENAME
2 BLAKE
5 CLARK
6 GEETHA
AIM
Add a new Column AGE to Employee table and Display it.
QUERY
ALTER TABLE EMP ADD(AGE INT(2));
SELECT * FROM EMP;
OUTPUT
52 | P a g e
6 GEETHA CLERK F 1981-02-22 NULL NULL NULL
AIM
Modify the size of the column ENAME into CHAR(25) using ALTER command and display the table
structure.
QUERY
ALTER TABLE EMP MODIFY ENAME CHAR(25);
DESCRIBE EMP;
OUTPUT
FIELD TYPE NULL KEY DEFAULT EXTRA
ENO int(11) NO PRI NULL
ENAME char(25) YES UNI NULL
JOB varchar(25) YES CLERK
GENDER char(1) NO NULL
HIRE date YES NULL
SAL float(6,2) YES NULL
COMM int(11) YES NULL
AGE int(2) YES NULL
AIM
Add Pri03y key constraints to the column ENO in the SALARY1 table and Describe it.
QUERY
ALTER TABLE SALARY1 ADD PRI03Y KEY(ENO);
DESCRIBE SALARY1;
OUTPUT
ENO Int(11) NO PRI NULL
ENAME Varchar(20) YES NULL
JOINS
AIM
Display Cid,Ename,Pid,Pname,Manufac From client and Product table whose having matching PID.
53 | P a g e
QUERY
SELECT CID,ENAME,CLIENT.PID,PNAME,MANUFAC
FROM CLIENT,PRODUCT
WHERE CLIENT PID=PRODUCT.PID;
OUTPUT
NATURAL JOIN
AIM
QUERY
SELECT *
FROM CLIENT
NATURAL JOIN PRODUCT;
OUTPUT
54 | P a g e
FW12 15 PRETTY WOMAN DELHI FACE WASH XYZ 95
55 | P a g e