0% found this document useful (0 votes)
176 views40 pages

Grade XII - Computer Science Practical Manual

Hi

Uploaded by

rakeshgravan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
176 views40 pages

Grade XII - Computer Science Practical Manual

Hi

Uploaded by

rakeshgravan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

COMPUTER SCIENCE

PRACTICAL

MANUAL

CLASS: XII

1
INDEX

EXP NO TITLE PAGE NO *


1 FACTORIAL OF A NUMBER 3

2 FIBONACCI SERIES 4

3 STRING PALINDROME 5

4 RANDOM NUMBER 6

5 LIST ROTATION 7

6 FREQUENCIES OF ELEMENT 8

7 PRIME NUMBER 9

8 SIMPLE INTEREST 10

9 TEXT FILE – READ LINE BY LINE 11

10 TEXT FILE – COPY LINES 12

11 TEXT FILE – COUNT CHARACTERS 13

12 CSV – READ AND WRITE OPERATION 15

13 BINARY FILE – CREATE AND SEARCH RECORD 17

14 BINARY FILE -CRATE AND UPDATE RECORD 19

15 STACK – PUSH AND POP OPERATION 22

16 SQL – COMPANY AND CUSTOMER TABLE 23

17 SQL – TEACHER TABLE 25

18 PYTHON APPLICATION WITH MYSQL – FETCH RECORDS 27

19 PYTHON APPLICATION WITH MYSQL – COUNT RECORDS 28

20 PYTHON APPLICATION WITH MYSQL – SEARCH RECORD 29

21 PYTHON APPLICATION WITH MYSQL – DELETE RECORD 30

22 SQL – STUDENT TABLE 31

23 SQL – DOCTOR AND SALARY TABLE 33

24 SQL – MARK TABLE – AGGREGATE FUNCTIONS 35

* DON’T WRITE THE GIVEN PAGE NUMBER IN THE RECORD NOTEBOOK.

2
1. FACTORIAL OF A NUMBER

AIM:

To write a program to find the factorial of a given number.

PROGRAM:

def factorial (num) :

fact = 1

for i in range (1,num+1) :

fact = fact*i

return fact

number = int ( input ( ‘Please enter any number to find factorial:’ ))

result = factorial (number)

print ( ‘The factorial of’ , number , ‘is ; ‘ , result )

OUTPUT

Please enter any number to find factorial: 5

The factorial of 5 is ; 120

RESULT:

The program was successfully executed and desired output was obtained.

3
2. FIBONACCI SERIES

AIM:

To write a program to find the Fibonacci series of a given number.

PROGRAM:

n = int ( input ( ‘Enter the value of n to generate a Fibonacci series:’ ))

a=0

b=1

sum = 0

count = 1

print (‘Fibonacci series: ‘ , end = ' ' )

while (count<= n ) :

print(sum, end = ' ' )

count += 1

a=b

b = sum

sum = a +b

OUTPUT

Enter the value of n to generate a Fibonacci series: 6

Fibonacci series: 0 1 1 2 3 5

RESULT:

The program was successfully executed and desired output was obtained.

4
3. STRING PALINDROME

AIM:

To write a program to check whether the given string is palindrome or not.

PROGRAM:

def ispalindrome (str) :

for i in range ( 0 , int ( len (str)/2 ) ) :

if str [i] != str [len(str) - i - 1] :

return False

return True

s = input ( ‘Enter String : ‘)

ans = ispalindrome (s)

if (ans) :

print ( ‘The given string is a palindrome ‘ )

else :

print ( ‘The given string is not a palindrome’ )

OUTPUT

Enter String : vowel

The given string is not a palindrome

Enter String : malayalam

The given string is a palindrome

RESULT:

The program was successfully executed and desired output was obtained.

5
4. RANDOM NUMBER GENERATOR

AIM:

To write a program to generate random number between 1 and 6. (Simulate a dice)

PROGRAM:

import random

def rolladice () :

r = random.randint (1,6)

return r

print (‘Rolling a dice ‘ )

n = ‘y’

while ( n== 'y') :

n = input (‘Enter y/n to roll a dice and get a random number :’)

if n == 'y' :

print (rolladice())

OUTPUT

Rolling a dice

Enter y/n to roll a dice and get a random number :y

Enter y/n to roll a dice and get a random number :n

RESULT:

The program was successfully executed and desired output was obtained.

6
5. LIST ROTATION

AIM:

To write a program to perform left and right rotation of list.

PROGRAM:

n = int (input ( ‘Enter the value of N : ‘ ))

testlist = [1,4,6,7,2,]

print (‘Original list : ‘ + str (testlist))

testlist= testlist [n:] + testlist[:n]

print (‘List after left rotate by 3 : ‘ + str (testlist) )

testlist = testlist [-n:] + testlist[:-n]

print ( ‘List after right rotate by 3 (back to original :’+str(testlist))

OUTPUT

Enter the value of n : 2

Original list : [1, 4, 6, 7, 2]

List after left rotation by 3 : [6, 7, 2, 1, 4]

List after right rotation by 3 (back to original :[1, 4, 6, 7, 2]

RESULT:

The program was successfully executed and desired output was obtained.

7
6. FREQUENCIES OF ELEMENTS

AIM:

To write a program to display frequencies of all the elements of a list.

PROGRAM:

L = [3,21,5,6,3,8,21,6]

L1= []

L2=[]

for i in L :

if i not in L2 :

x = L.count(i)

L1.append(x)

L2.append(i)

print ( ‘Element \t \t \t ‘ , ‘ Frequency ‘ )

for i in range (len(L1)):

print (L2[i] , '\t \t \t' , L1[i])

OUTPUT

Element Frequency

3 2

21 2

5 1

6 2

8 1

RESULT:

The program was successfully executed and desired output was obtained.

8
7. PRIME NUMBER

AIM:

To write a program to check prime number.

PROGRAM:

import math

num = int (input ( ‘Enter any number : ‘ ))

isprime = True

for i in range (2, int(math.sqrt(num))+1):

if num %i == 0:

isprime=False

break

if isprime :

print (‘The given number is prime’ )

else :

print (‘The given number is not prime ‘ )

OUTPUT

Enter any number : 5

The given number is prime

Enter any number : 15

The given number is not prime

RESULT:

The program was successfully executed and desired output was obtained.

9
8. SIMPLE INTEREST

AIM:

To write a program to calculate simple interest.

PROGRAM:

def simpleinterest(p,n ) :

if p> 30000:

return p*n*7/100

elif p> 20000 and p<= 30000:

return p*n*5/100

else :

return p*n*3/100

p = int (input (‘Enter the principal amount: ‘ ))

n = int(input (‘Enter the number of years : ‘))

print (‘Simple Interest : ‘ , simpleinterest(p,n) )

OUTPUT

Enter the principal amount: 50000

Enter the number of years : 5

Simple Interest : 17500.0

RESULT:

The program was successfully executed and desired output was obtained.

10
9. TEXT FILE – READ AND DISPLAY WORD WITH #

AIM:

To write a program to read text file line by line and display each word separated by #.

myfile.txt content

For every action there is equal and opposite reaction.

Energy can neither be created nor be destroyed.

PROGRAM:

fin = open (‘myfile.txt’,'r')

contents = fin.readlines()

for line in contents :

words = line.split ()

for i in words :

print ( i , end = ‘#’)

fin.close()

OUTPUT

For# every# action# there# is# equal# and# opposite# reaction.#

Energy# can# neither# be# created# nor# be# destroyed.#

RESULT:

The program was successfully executed and desired output was obtained.

11
10. TEXT FILE - COPY LINES

AIM:

To write a program to copy all the lines containing the character ‘a’ or ‘A’ from a
file to another file.

file1.txt Contents

Betty bought some butter

But the butter was bitter

So Betty bought some better butter

To make bitter butter better

PROGRAM:

fin = open (‘file1.txt’ , 'r')

fout = open (‘file2.txt’ , 'w')

contents = fin.readlines ()

for line in contents :

for i in line :

if i in['a' ,'A']:

fout.write(line)

break

fin.close()

fout.close()

OUTPUT – file2.txt Contents

But the butter was bitter

To make bitter butter better

RESULT:

The program was successfully executed and desired output was obtained.

12
11. TEXT FILE - COUNT CHARACTERS

AIM:

To write a program to count number of vowels, consonants, lower and uppercase


letters.

science.txt contents

For every action there is equal and opposite reaction.

Energy can neither be created nor be destroyed.

PROGRAM:

def cnt () :

fin=open (‘science.txt',’r’)

contents = fin.read()

vowels=0

cons=0

lower=0

upper=0

for ch in contents :

if ch.islower():

lower +=1

elif ch.isupper () :

upper +=1

ch = ch.lower ()

if ch in [‘a’, ‘e’ , ‘i’ , ‘o’ , ‘u’ ]:

vowels +=1

elif ch in [‘b’,’c’,’d’,’f’,’g’,’h’,’j’,’k’,’l’,’m’,’n’,’p’,’q’,’r’,’s’,’t’,’v’,’w’,’x’,’y’,’z’ ]:

cons +=1

fin.close ()

print (‘No of vowels are’ ,vowels)

print (‘No of consonants are’ , cons)

print (‘No of lower case letters are’ , lower)

13
print (‘No of upper case letters are’ , upper)

cnt ()

OUTPUT:

No of vowels are 36

No of consonants are 48

No of lower case letters are 82

No of upper case letters are 2

RESULT:

The program was successfully executed and desired output was obtained.

14
12. CREATE A CSV FILE

AIM:

To write a program to create a CSV file to store used id and password.

PROGRAM:

import csv

with open (‘user.csv’ , 'w' ) as fout :

writer = csv.writer(fout)

while True :

userid = input(‘Enter id ‘ )

password = input (‘Enter password’ )

writer.writerow ([‘userId’, ‘Password ‘ ])

record= [userid, password]

fout.writerow(record)

x= input ( ‘Press y to continue and n to terminate the program \n’ )

if x not in ‘yY’ :

break

with open (‘user.csv’ , 'r') as fin:

reader = csv.reader(fin)

uid = input (‘Enter the user id to be searched \n’ )

for i in reader :

next(reader)

if i [0]==uid:

print(i[1])

break

OUTPUT

Enter id 1

Enter password: abc

Press y to continue and n to terminate the program

15
Enter id 2

Enter password: xyz

Press y to continue and n to terminate the program

Enter the user id to be searched

abc

RESULT:

The program was successfully executed and desired output was obtained.

16
13. BINARY FILE - CREATE AND SEARCH RECORDS

AIM:

To write a program to create a binary file and to search a record.

PROGRAM:

import pickle

stud={}

fout=open ('student.dat' , ‘wb’)

ans = 'y'

while ans == 'y':

rno = int (input (‘Enter roll no ‘ ))

name = input (‘Enter your name’ )

mark1= int (input(‘Enter English mark’ ) )

mark2= int (input(‘Enter Math marks’))

mark3= int (input(‘Enter Science marks’))

stud[‘Rollno’] = rno

stud[‘Name’] = name

stud[‘Mark1’] = mark1

stud[‘Mark2’]=mark2

stud[‘Mark3’]=mark3

pickle.dump(stud,fout)

ans=input(‘Do you want to enter more data’)

fout.close()

fin = open (‘student.dat’ , ‘rb’ )

stud1 = {}

found = False

r = int(input(‘Enter the roll number to search’ ))

try :

while True:

17
stud1 = pickle.load(fin)

if stud1[‘Rollno’] == r :

print (‘students details ‘ )

print (stud1)

found = True

except :

if found== False :

print (‘Record not found’)

else:

print (‘Record found’ )

fin.close()

OUTPUT

Enter roll no 101

Enter your name Arun

Enter English mark 56

Enter Math marks 65

Enter Science marks 76

Do you want to enter more data y

Enter roll no 102

Enter your name Bala

Enter English mark 66

Enter Math marks 78

Enter Science marks 56

Do you want to enter more data n

Enter rno to search 101

Students details

{'Rollno': 101, 'Name': 'Arun', 'Mark1': 56, 'Mark2': 65, 'Mark3': 76}

Record found

RESULT:

The program was successfully executed and desired output was obtained.

18
14. BINARY FILE - CREATE AND UPDATE RECORDS

AIM:

To write a program to create a binary file and update a record.

PROGRAM:

import pickle

stud={}

fout =open (‘student.dat' , ‘wb’)

ans = 'y'

while ans == 'y':

rno = int (input ( ‘Enter Roll no ‘ ))

name = input ( ‘Enter the name’ )

mark1= int (input(‘Enter English mark’ ) )

mark2= int (input(‘Enter Math marks’))

mark3= int (input(‘Enter Science marks’))

stud[‘Rollno’] = rno

stud[‘Name’] = name

stud[‘Mark1’] = mark1

stud[‘Mark2’]=mark2

stud[‘Mark3’]=mark3

pickle.dump(stud,fout)

ans=input(‘Do you want to enter more data’)

fout.close()

stud1 = {}

found = False

fin = open (‘student.dat’ , ‘rb+’ )

r= input(‘Enter rno to search ‘ )

try :

while True:

19
rpos = fin.tell()

stud1 = pickle.load(fin)

if stud1[‘Rollno’] == r:

stud1[‘Mark1’] += 5

fin.seek (rpos)

pickle.dump (stud1, fin)

print (‘Students details ‘ )

print (stud1)

found = True

except :

if found== False :

print (‘Record not found’)

else:

print (‘Record found and updated’ )

fin.close()

OUTPUT

Enter roll no 101

Enter your name Arun

Enter English mark 56

Enter Math marks 65

Enter Science marks 76

Do you want to enter more data y

Enter roll no 102

Enter your name Bala

Enter English mark 66

Enter Math marks 78

Enter Science marks 56

Do you want to enter more data n

Enter rno to search 101

Students details

20
{'Rollno': 101, 'Name': 'Arun', 'Mark1': 61, 'Mark2': 65, 'Mark3': 76}

Record found and updated

RESULT:

The program was successfully executed and desired output was obtained.

21
15. STACK – PUSH AND POP OPERATION

AIM:

To write a program to implement stack PUSH() and POP() operation using list.

PROGRAM:

travel = []

def pushelement (nlist) :

for row in nlist:

if row[1] !=‘India’ and row[2] < 3500:

travel.append([row[0], row[1]])

def popelement () :

while len (travel) :

print (travel.pop())

else :

print (‘Stack empty ‘ )

nlist = [[‘New York ‘ , ‘US’ , 11734 ] , [‘Naypyidaw’ , ‘Myanmar’ , 5219 ], [‘Dubai’ , ‘UAE’ ,
2194 ], [‘London’ , ‘England’ , 6693], [‘Colombo’ , ‘Srilanka’ , 3405 ]]

pushelement(nlist)

popelement()

OUTPUT

['Colombo', 'Srilanka']

['Dubai', 'UAE']

Stack empty

RESULT:

The program was successfully executed and desired output was obtained.

22
16. SQL - COMPANY AND CUSTOMER TABLE

AIM:

To create table company and customer. Write and execute queries for the question 1
to 5.

TABLE: COMPANY

CID NAME CITY PRODUCTNAME


111 SONY DELHI TV
222 NOKIA MUMBAI MOBILE
333 ONIDA DELHI TV
444 SONY MUMBAI MOBILE
555 BLACKBERRY CHENNAI MOBILE
666 DELL DELHI LAPTOP

TABLE: CUSTOMER

CUSTID NAME PRICE QTY CID


101 ROHAN SHARMA 70000.00 20 222
102 DEEPAK SHARMA 50000.00 10 666
103 MOHAN KUMAR 30000.00 5 111
104 SAHIL BANSAL 35000.00 3 333
105 NEHA SONI 25000.00 7 444
106 SONAL 20000.00 5 333
107 ARUN SINGH 50000.00 15 666

1. To display those company name which are having price less than 30000

SELECT COMPANY.NAME FROM COMPANY, CUSTOMER WHERE


COMPANY.CID=CUSTOMER.CID AND PRICE <30000;

OUTPUT

NAME
ONIDA
SONY

2. To display the name of the companies in reverse alphabetical order.

SELECT NAME FROM COMPANY ORDER BY NAME DESC;

OUTPUT

NAME
SONY
ONIDA
23
NOKIA
DELL
BLACK BERRY

3. To increase the price by 1000 for those customers whose name starts with ‘S’

UPDATE CUSTOER SET PRICE = PRICE + 1000 WHERE NAME LIKE ‘S%’;

OUTPUT

Query OK, 1 rows affected

4. To add one more column TOTALPRICE with float type to the table customer.

ALTER TABLE CUSTOMER ADD TOTALPRICE FLOAT;

OUTPUT

Query OK, 0 rows affected

5. To display the details of company where PRODCUTNAME as MOBILE.

SELECT * FROM COMPANY WHERE PRODUCTNAME=’MOBILE’;

OUTPUT

CID NAME CITY PRODUCTNAME


222 NOKIA MUMBAI MOBILE
444 SONY MUMBAI MOBILE
555 BLACK BERRY CHENNAI MOBILE

RESULT:

The queries were successfully executed and desired output was obtained.

24
17. SQL – TEACHER TABLE

AIM:

To create table teacher. Write and execute queries for the question 1 to 5.

TABLE: TEACHER

NO NAME AGE DEPARTMENT DATEOFJOIN SALARY SEX


1 JISHNU 34 COMPUTER 1997-01-10 12000 M
2 SHARMILA 31 HISTORY 1998-08-24 20000 F
3 SANTHOSH 32 MATHS 1996-12-12 30000 M
4 SHAMATHI 35 HISTORY 1999-07-01 40000 F
5 RAGU 42 MATHS 1997-09-05 25000 M
6 SHIVA 50 HISTORY 1997-02-25 30000 M
7 SANTHI 44 COMPUTER 1997-02-25 21000 F
8 SHRIYA 33 MATHS 1997-07-31 20000 F

1. To delete all information about the teacher of HISTORY department.

DELETE FROM TEACHER WHERE DEPARTMENT=’HISTORY’;

OUTPUT

Query OK, 3 rows affected

2. To display distinct department in ascending order.

SELECT DISTINCT DEPARTMENT FROM TEACHER ORDER BY DEPARTMENT;

OUTPUT

DISTINCT DEPARTMENT
COMPUTER
MATHS

3. To display average salary, minimum salary gender wise.

SELECT SEX, AVG(SALARY), MIN(SALARY) FROM TEACHER GROUP BY SEX;

OUTPUT

SEX AVG(SALARY) MIN(SALARY)


M 23600 12000
F 26666 20000

4. To count the number of teachers with age above 35.

SELECT COUNT(*) FROM TEACHER WHERE AGE > 35;

OUTPUT
25
COUNT(*)
3

5. To count the number of teacher department wise.

SELECT DEPARTMENT, COUNT(*) FROM TEACHER GROUP BY DEPARTMENT;

OUTPUT

DEPARTMENT COUNT(*)
COMPUTER 2
MATHS 3

RESULT:

The queries were successfully executed and desired output was obtained.

26
18.PYTHON APPLICATION WITH MYSQL – FETCH RECORDS

AIM:

To write a program to display records from MYSQL database table.

PROGRAM:

import mysql.connector as sqltor

mycon= sqltor.connect(host='localhost' , user = 'root' , passwd = '123456' , database =


'schooldb' )

if mycon.is_connected()==False :

print(‘Error connecting to mysql database’)

cursor=mycon.cursor()

cursor.execute(“SELECT * FROM COMPANY”)

data = cursor.fetchall()

for row in data :

print(row)

mycon.close()

OUTPUT

(111, 'SONY', 'DELHI', 'TV')

(222, 'NOKIA', 'MUMBAI', 'MOBILE')

(333, 'ONIDA', 'DELHI', 'TV')

(444, 'SONY', 'MUMBAI', 'MOBILE')

(555, 'BLACK BERRY', 'CHENNAI', 'MOBILE')

(666, ‘DELL’, ‘DELHI’, ‘ LAPTOP’)

RESULT

The program was successfully executed and desired output was obtained.

27
19.PYTHON APPLICATION WITH MYSQL – COUNT RECORDS

AIM:

To write a program to count records from MYSQL database table.

PROGRAM:

import mysql.connector as sqltor

mycon= sqltor.connect(host='localhost' , user = 'root' , passwd = '123456' , database =


'schooldb' )

if mycon.is_connected()==False :

print(‘Error connecting to mysql database’)

cursor=mycon.cursor()

cursor.execute(“SELECT * FROM COMPANY”)

data = cursor.fetchone()

count=cursor.rowcount

print (‘Total number of rows retrieved from result set’ , count)

data = cursor.fetchone()

count=cursor.rowcount

print (‘Total number of rows retrieved from result set’ , count)

data = cursor.fetchmany(3)

count=cursor.rowcount

print (‘Total number of rows retrieved from result set’ , count)

mycon.close()

OUTPUT

Total number of rows retrieved from result set 1

Total number of rows retrieved from result set 2

Total number of rows retrieved from result set 5

RESULT

The program was successfully executed and desired output was obtained.

28
20.PYTHON APPLICATION WITH MYSQL - SEARCH RECORD

AIM:

To write a program to search record from MYSQL database table.

PROGRAM:

import mysql.connector as sqltor

mycon= sqltor.connect(host='localhost' , user = 'root' , passwd = '123456' , database =


'schooldb' )

if mycon.is_connected()==False :

print(‘Error connecting to mysql database’)

id= int(input(‘Enter company id : ‘))

cursor=mycon.cursor()

cursor.execute(“SELECT * FROM COMPANY WHERE CID=%s”%(id,))

data = cursor.fetchone()

print(data)

mycon.close()

OUTPUT

Enter company id : 111

(111, 'SONY', 'DELHI', 'TV')

RESULT

The program was successfully executed and desired output was obtained.

29
21.PYTHON APPLICATION WITH MYSQL - DELETE RECORD

AIM:

To write a program to delete record from MYSQL database table.

PROGRAM:

import mysql.connector as sqltor

mycon= sqltor.connect(host='localhost' , user = 'root' , passwd = '123456' , database =


‘schooldb’ )

if mycon.is_connected()==False :

print(‘Error connecting to mysql database’)

id= int(input(‘Enter company id : ‘))

cursor=mycon.cursor()

cursor.execute(“DELETE FROM COMPANY WHERE CID={}”.format(id))

print(‘Record Deleted’)

mycon.commit()

mycon.close()

OUTPUT

Enter company id : 111

Record Delete

RESULT

The program was successfully executed and desired output was obtained.

30
22. SQL – TABLE STUDENT

AIM:

To create table student. Write and execute queries for the question 1 to 5.

TABLE: STUDENT

NO NAME STIPEND STREAM AVGMARK GRADE CLASS


1 KARAN 400.00 SCIENCE 78.5 B 12B
2 DIVYA 450.00 COMMERCE 68.6 C 12A
3 ROBERT 500.00 HUMANITIES 90.6 A 11A
4 RUBINA 350.00 SCIENCE 64.4 C 12B
5 MOHAN 300.00 COMMERCE 67.5 C 12C

1. Alter table to add new column DOB Date in student table.

ALTER TABLE STUDENT ADD DOB DATE;

OUTPUT

Query OK, 0 rows affected

2. Alter table to change NO column to ROLLNO

ALTER TABLE STUDENT CHANGE NO ROLLNO INT;

OUTPUT

Query OK, 0 rows affected

3. Display all the science stream students from the table.

SELECT * FROM STUDENT WHERE STREAM=’SCIENCE’;


OUTPUT

NO NAME STIPEND STREAM AVGMARK GRADE CLASS


1 KARAN 400.00 SCIENCE 78.5 B 12B
4 RUBINA 350.00 SCIENCE 64.4 C 12B

4. Display all the records in descending order of AVGMARK

SELECT * FROM STUDENT ORDER BY AVGMARK DESC;

OUTPUT

NO NAME STIPEND STREAM AVGMARK GRADE CLASS


3 ROBERT 500.00 HUMANITIES 90.6 A 11A
1 KARAN 400.00 SCIENCE 78.5 B 12B
2 DIVYA 450.00 COMMERCE 68.6 C 12A
5 MOHAN 300.00 COMMERCE 67.5 C 12C

31
4 RUBINA 350.00 SCIENCE 64.4 C 12B

5. Display all records where stipend between 350 and 450

SELECT * FROM STUDENT WHERE STIPEND BETWEEN 350 AND 450;

OUTPUT

NO NAME STIPEND STREAM AVGMARK GRADE CLASS


1 KARAN 400.00 SCIENCE 78.5 B 12B
2 DIVYA 450.00 COMMERCE 68.6 C 12A
4 RUBINA 350.00 SCIENCE 64.4 C 12B

RESULT:

The queries were successfully executed and desired output was obtained.

32
23. SQL – TABLE DOCTOR AND SALARY

AIM:

To create table doctor and salary. Write and execute queries for the question 1 to 5.

TABLE: DOCTOR

ID NAME DEPT SEX EXPERIENCE


101 JOHN ENT M 12
104 SMITH ORTHOPEDIC M 5
107 GEORGE CARDIOLOGY M 10
114 LARA SKIN F 3
109 K GEORGE MEDICINE F 9
105 JOHNSON ORTHOPEDIC M 10
117 LUCY ENT F 3
111 BILL MEDICINE M 12
130 MORPHY ORTHOPEDIC M 15
TABLE: SALARY

ID BASIC ALLOWANCE CONSULTATION


101 12000 1000 300
104 23000 2300 500
107 32000 4000 500
114 12000 5200 100
109 42000 1700 200
105 18900 1690 300
130 21700 2600 300

1. Display name of all doctors who are in MEDICINE department having more than
10 years of experience.

SELECT NAME FROM DOCTOR WHERE DEPT =’MEDICINE’ AND EXPERIENCE > 10;

OUTPUT

NAME
BILL

2. Display the average salary of all doctors working in ‘ ENT’ department. Where
salary = Basic + Allowance.

SELECT AVG(BASIC+ALLOWANCE) FROM DOCTOR D, SALARY S WHERE D.ID=S.ID


AND DEPT=’ENT’;

OUTPUT

AVG(BASIC+ALLOWANCE)

33
13000.00

3. Display minimum allowance of Female doctors.

SELECT MIN(ALLOWANCE) FROM DOCTOR D, SALARY S WHERE D.ID=S.ID AND


SEX=’F’;

OUTPUT

MIN(ALLOWANCE)
1700.00

4. Display Id, Name from the Doctor table and Basic, Allowance From Salary Table
with their matching Id.

SELECT D.ID,NAME,BASIC,ALLOWANCE FROM DOCTOR D, SALARY S WHERE


D.ID=S.ID;

OUTPUT

ID NAME BASIC ALLOWANCE


101 JOHN 12000 1000
104 SMITH 23000 2300
107 GEORGE 32000 4200
109 K GEORGE 42000 1700
114 LARA 12000 5200
130 MORPHY 21700 2600

5. To display distinct department from table doctor

SELECT DISTINCT DEPT FROM DOCTOR;

OUTPUT

DEPT
ENT
ORTHOPEDIC
CARDIOLOGY
SKIN
MEDICINE

RESULT:

The queries were successfully executed and desired output was obtained.

34
24. SQL - AGGREGATE FUNCTIONS

AIM:

To create table marks. Write and execute queries for the question 1 to 5.

TABLE: MARKS

SID COMPUTER PHYSICS CHEMISTRY BIOLOGY


101 89 67 58 90
102 78 98 65 45
103 56 78 83 97
104 99 48 69 75
105 87 48 79 60

1. To display sum of computer marks

SELECT SUM(COMPUER) FROM MARKS;

OUTPUT

SUM(COMPUTER)
409

2. To display average of computer marks

SELECT AVG(COMPUER) FROM MARKS;

OUTPUT

AVG(COMPUTER)
81.80

3. To count total records from the table

SELECT COUNT(*) FROM MARKS;

OUTPUT

COUNT(*)
5

4. To display minimum mark in biology

SELECT MIN(BIOLOGY) FROM MARKS;

OUTPUT

MIN(BIOLOGY)
45
35
5. To display maximum mark in chemistry

SELECT MAX(CHEMISTRY) FROM MARKS;

OUTPUT

MAX(CHEMISTRY)
83

RESULT:

The queries were successfully executed and desired output was obtained.

36
ANNEXURE

[Don’t write in record notebook. Only for practical]

CREATING DATABASE

CREATE DATABASE SCHOOLDB;

ACCESS DATABASE

USE SCHOOLDB;

EXP 16 - COMPANY AND CUSTOMER TABLE

TABLE: COMPANY

CID NAME CITY PRODUCTNAME


111 SONY DELHI TV
222 NOKIA MUMBAI MOBILE
333 ONIDA DELHI TV
444 SONY MUMBAI MOBILE
555 BLACKBERRY CHENNAI MOBILE
666 DELL DELHI LAPTOP

TABLE CREATION:

CREATE TABLE COMPANY (CID INT PRIMARY KEY, NAME VARCHAR(25), CITY
VARCHAR(25), PRODUCTNAME VARCHAR(25));

ADDING ROWS:

INSERT INTO COMPANY VALUES(111,’SONY’,’DELHI’,’TV’);

Similarly continue for other rows

TABLE: CUSTOMER

CUSTID NAME PRICE QTY CID


101 ROHAN SHARMA 70000.00 20 222
102 DEEPAK SHARMA 50000.00 10 666
103 MOHAN KUMAR 30000.00 5 111
104 SAHIL BANSAL 35000.00 3 333
105 NEHA SONI 25000.00 7 444
106 SONAL 20000.00 5 333
107 ARUN SINGH 50000.00 15 666

TABLE CREATION:

CREATE TABLE CUSTOMER (CUSTID INT PRIMARY KEY, NAME VARCHAR(25), PRICE
FLOAT, QTY INT, CID INT);

37
ADDING ROWS:

INSERT INTO CUSTOMER VALUES(101,’ROHAN SHARMA’,70000,20,222);

Similarly continue for other rows

EXP 17

TABLE: TEACHER

NO NAME AGE DEPARTMENT DATEOFJOIN SALARY SEX


1 JISHNU 34 COMPUTER 1997-01-10 12000 M
2 SHARMILA 31 HISTORY 1998-08-24 20000 F
3 SANTHOSH 32 MATHS 1996-12-12 30000 M
4 SHAMATHI 35 HISTORY 1999-07-01 40000 F
5 RAGU 42 MATHS 1997-09-05 25000 M
6 SHIVA 50 HISTORY 1997-02-25 30000 M
7 SANTHI 44 COMPUTER 1997-02-25 21000 F
8 SHRIYA 33 MATHS 1997-07-31 20000 F
TABLE CREATION:

CREATE TABLE TEACHER (NO INT PRIMARY KEY, NAME VARCHAR(25), AGE INT,
DEPARTMENT VARCHAR(25), DATEOFJOIN DATE, SALARY INT, SEX VARCHAR(1));

ADDING ROWS:

INSERT INTO TEACHER VALUES(1,’JISHNU’,34,’COMPUTER’,’1997-01-10’,12000,’M’);

Similarly continue for other rows

EXP 22

TABLE: STUDENT

NO NAME STIPEND STREAM AVGMARK GRADE CLASS


1 KARAN 400.00 SCIENCE 78.5 B 12B
2 DIVYA 450.00 COMMERCE 68.6 C 12A
3 ROBERT 500.00 HUMANITIES 90.6 A 11A
4 RUBINA 350.00 SCIENCE 64.4 C 12B
5 MOHAN 300.00 COMMERCE 67.5 C 12C

TABLE CREATION:

CREATE TABLE STUDENT (NO INT PRIMARY KEY, NAME VARCHAR(25), STIPEND
FLOAT, STREAM VARCHAR(25), AVGMARK FLOAT, GRADE VARCHAR(1), CLASS
VARCHAR(5));

ADDING ROWS:

INSERT INTO STUDENT VALUES(1,’KARAN’,400,’SCIENCE’,78.5,’B’,’12B’);

Similarly continue for other rows


38
EXP 23
TABLE: DOCTOR

ID NAME DEPT SEX EXPERIENCE


101 JOHN ENT M 12
104 SMITH ORTHOPEDIC M 5
107 GEORGE CARDIOLOGY M 10
114 LARA SKIN F 3
109 K GEORGE MEDICINE F 9
105 JOHNSON ORTHOPEDIC M 10
117 LUCY ENT F 3
111 BILL MEDICINE M 12
130 MORPHY ORTHOPEDIC M 15

TABLE CREATION:

CREATE TABLE DOCTOR (ID INT PRIMARY KEY, NAME VARCHAR(25), DEPT
VARCHAR(25), SEX VARCHAR(1), EXPERIENCE INT);

ADDING ROWS:

INSERT INTO DOCTOR VALUES(101,’JOHN’,ENT’,’M’,12);

Similarly continue for other rows

TABLE: SALARY

ID BASIC ALLOWANCE CONSULTATION


101 12000 1000 300
104 23000 2300 500
107 32000 4000 500
114 12000 5200 100
109 42000 1700 200
105 18900 1690 300
130 21700 2600 300

TABLE CREATION:

CREATE TABLE SALARY (ID INT PRIMARY KEY, BASIC INT, ALLOWANCE INT,
CONSULTATION INT );

ADDING ROWS:

INSERT INTO SALARY VALUES(101,12000,1000,300);

Similarly continue for other rows

39
EXP 24

TABLE: MARKS

SID COMPUTER PHYSICS CHEMISTRY BIOLOGY


101 89 67 58 90
102 78 98 65 45
103 56 78 83 97
104 99 48 69 75
105 87 48 79 60

TABLE CREATION:

CREATE TABLE MARKS (SID INT PRIMARY KEY,COMPUTER INT, PHYSICS INT,
CHEMISTY INT, BIOLOGY INT);

ADDING ROWS:

INSERT INTO MARKS VALUES(101,89,67,58,90);

Similarly continue for other rows

40

You might also like