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

Practical Question

Practical question for class 12th cbse boards practical computer science

Uploaded by

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

Practical Question

Practical question for class 12th cbse boards practical computer science

Uploaded by

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

Q1.

In a Database, there are two tables given below:


Table : EMPLOYEE
EMPLOYEEID NAME SALES JOBID

E1 SUMIT SINHA 1100000 102

E2 VIJAY SINGH TOMAR 1300000 101

E3 AJAY RAJPAL 1400000 103

E4 MOHIT RAMNANI 1250000 102

E5 SHAILJA SINGH 1450000 103


Table : JOB
JOBID JOBTITLE SALARY

101 President 200000

102 Vice President 125000

103 Administration Assistant 80000

104 Accounting Manager 70000

105 Accountant 65000

106 Sales Manager 80000


Write SQL Queries for the following:
1. To display employee ids, names of employees, job ids with corresponding job titles.
2. To display names of employees, sales and corresponding job titles who have achieved sales more
than 1300000.
3. To display names and corresponding job titles of those employees who have 'SINGH' (anywhere) in
their names.
4. Identify foreign key in the table EMPLOYEE.
5. Write SQL command to change the JOBID to 104 of the EMPLOYEE with ID as E4 in the table
'EMPLOYEE'.
Answer
1. SELECT EMPLOYEE.EMPLOYEEID, EMPLOYEE.NAME, EMPLOYEE.JOBID, JOB.JOBTITLE
FROM EMPLOYEE, JOB WHERE EMPLOYEE.JOBID = JOB.JOBID;
Output
+------------+-------------------+-------+--------------------------+
| EMPLOYEEID | NAME | JOBID | JOBTITLE |
+------------+-------------------+-------+--------------------------+
| E1 | SUMIT SINHA | 102 | VICE PRESIDENT |
| E2 | VIJAY SINGH TOMAR | 101 | PRESIDENT |
| E3 | AJAY RAJPAL | 103 | ADMINISTARTION ASSISTANT |
| E4 | MOHIT RAMNANI | 102 | VICE PRESIDENT |
| E5 | SHAILJA SINGH | 103 | ADMINISTARTION ASSISTANT |
+------------+-------------------+-------+--------------------------+
2. SELECT EMPLOYEE.NAME, EMPLOYEE.SALES, JOB.JOBTITLE FROM EMPLOYEE, JOB
WHERE EMPLOYEE.JOBID = JOB.JOBID AND EMPLOYEE.SALES > 1300000;
Output
+---------------+---------+--------------------------+
| NAME | SALES | JOBTITLE |
+---------------+---------+--------------------------+
| AJAY RAJPAL | 1400000 | ADMINISTARTION ASSISTANT |
| SHAILJA SINGH | 1450000 | ADMINISTARTION ASSISTANT |
+---------------+---------+--------------------------+
3. SELECT EMPLOYEE.NAME, JOB.JOBTITLE FROM EMPLOYEE, JOB WHERE EMPLOYEE.JOBID
= JOB.JOBID AND EMPLOYEE.NAME LIKE '%SINGH%';
Output
+-------------------+--------------------------+
| NAME | JOBTITLE |
+-------------------+--------------------------+
| VIJAY SINGH TOMAR | PRESIDENT |
| SHAILJA SINGH | ADMINISTARTION ASSISTANT |
+-------------------+--------------------------+
4. In the given tables, EMPLOYEE and JOB, the JOBID column in the EMPLOYEE table is a foreign key
referencing the JOBID column in the JOB table.
5. UPDATE EMPLOYEE SET JOBID = 104 WHERE EMPLOYEEID = 'E4';
Output
SELECT * FROM EMPLOYEE ;
+------------+-------------------+---------+-------+
| EMPLOYEEID | NAME | SALES | JOBID |
+------------+-------------------+---------+-------+
| E1 | SUMIT AINHA | 1100000 | 102 |
| E2 | VIJAY SINGH TOMAR | 1300000 | 101 |
| E3 | AJAY RAJPAL | 1400000 | 103 |
| E4 | MOHIT RAMNANI | 1250000 | 104 |
| E5 | SHAILJA SINGH | 1450000 | 103 |
+------------+-------------------+---------+-------+
Q2. Write a Program in Python that defines and calls the following user defined functions:
(a) add(). To accept and add data of an employee to a CSV file 'furdata.csv'. Each record consists of a
list with field elements as fid, fname and fprice to store furniture id, furniture name and furniture
price respectively.
(b) search(). To display the records of the furniture whose price is more than 10000.
Answer
import csv
def add():
with open('furdata.csv', mode='a', newline='') as file:
writer = csv.writer(file)
fid = input("Enter furniture id: ")
fname = input("Enter furniture name: ")
fprice = float(input("Enter furniture price: "))
writer.writerow([fid, fname, fprice])
print("Record added successfully to 'furdata.csv'")
def search():
found = False
with open('furdata.csv', mode='r') as file:
reader = csv.reader(file)
print("Records of furniture with price more than 10000:")
for row in reader:
if len(row) == 3 and float(row[2]) > 10000:
print("Furniture ID:", row[0])
print("Furniture Name:", row[1])
print("Furniture Price:", row[2])
print()
found = True
if found == False:
print("No records of furniture with price more than 10000 found")

add()
search()

Output
Enter furniture id: 9
Enter furniture name: desk
Enter furniture price: 3000
Record added successfully to 'furdata.csv'
Records of furniture with price more than 10000:
Furniture ID: 1
Furniture Name: table
Furniture Price: 20000
Furniture ID: 2
Furniture Name: chair
Furniture Price: 12000

You might also like