0% found this document useful (0 votes)
16 views9 pages

SQL Connectivity Class Test Qp&Ms 2

Sql

Uploaded by

lebronalex312
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)
16 views9 pages

SQL Connectivity Class Test Qp&Ms 2

Sql

Uploaded by

lebronalex312
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/ 9

1.

Consider the table Employee in the database “PAYROLL” with the following
credentials : Host – “localhost”, username – “root”, password – “sql@123”
Table - EMPLOYEE
EMPNO ENAME DESIG SALARY LEAVE BONUS
121 RAM SUNDAR MANAGER 50000 3 3000
122 KAVYA SALES EXECUTIVE 30900 4 2300
123 FARAZ SUPERVISOR 40200 2 2400
Complete the given Python program by filling up the blank lines to connect with

MySQL using database connectivity as directed in the questions (i) to (iv)

import mysql.connector as ms
mycon=ms.connect(________________________________) #statement 1
if mycon.is_connected():
print("Successful")
cursor=_________________ #statement 2
cursor.execute("create table Employee(empno int primary key, ename varchar(20),
desig varchar(20),salary float(8,2),leave int, bonus float(7,2))")
mycon.commit()
for i in range(3):
eno=int(input("Enter the Employee number "))
ename=input("Enter the Employee name ")
desig=input("Enter the designation ")
sal=float(input("Enter the salary "))
lea=float(input("Enter the leave details "))
bon=float(input("Enter the bonus details "))
cursor.execute(________________________________) # statement 3
cursor.execute("select * from Employee")
data=______________________ #statement 4
count=cursor.rowcount
print("Rows: ",count)
for row in data:
print(row)
i) Complete the statement #1 to write appropriate missing parameters.
(Use default values for the parameters)
ii) Write Statement #2 to create the cursor object
iii) Write the necessary command for statement #3 to insert the record from the inputs
given by the user
iv) Complete the statement #4, to fetch all the records from the result set.
Answers

1 mycon=ms.connect(host=”localhost”, user=”root”, passwd=”sql@123”, database=


“PAYROLL”)
2. cursor=mycon.cursor()
3. cursor.execute(“insert into Employee values(%s,’%s’,’%s’,%s,%s)”%(eno,
ename,desig,sal,lea,bon))
4. data=cursor.fetchall()
2. Consider the following STUDENT table.

Table - STUDENT
ADMNO SNAME GENDER DOB STREAM AVERAGE
JC1234 KAMAL MALE 2000-09-09 SCIENCE 94
JC1324 SUPRIYA FEMALE 2001-08-07 COMMERCE 76
JC3456 VARAHAN MALE 2002-07-06 SCIENCE 67

Complete the given Python program by filling up the blank lines to connect with

MySQL using database connectivity as directed in the questions (i) to (iv)

import mysql.connector as sq
mycon=sq.connect(host="localhost",user="root",passwd="admin",database="school")
if mycon.is_connected():
print("Successful")
cursor=_____________ #statement 1
cursor.execute(_________________________) #statement 2
cursor.execute("insert into Student values (‘JC1234’,’KAMAL’,’MALE’,’2000-09-09’,’SCIENCE’,94)”)
cursor.execute("insert into Student values (‘JC1324’,’SUPRIYA’,’FEMALE’,’2001-08- 7’, ’COMMERCE’,76)”)
cursor.execute("insert into Student values(‘JC3456’,’VARAHAN’,’MALE’,’2002-07-06’,’SCIENCE’,67)”)
mycon.__________________ #statement 3
cursor.execute(_______________) #statement 4
data=cursor.fetchall()
print(data)

i) Complete the statement #1 to create the cursor object.


ii) Write Statement #2 to create the table student.
iii) Write the necessary command for statement #3 to save the operation.
iv) Complete the statement #4, to extract the student records whose average is > 90.
Answers

1. Cursor=mycon.cursor()
2. Cursor.execute(“create table STUDENT(ADMNO varchar(10), SNAME varchar(10),
GENDER varchar(10), DOB date, SNAME varchar(10), AVERAGE int)”)
3. mycon.commit()
4. Cursor.execute(“select * from STUDENT where average>90
3. Consider the tables WORKER and PAYLEVEL are already created and
available in the database ADMIN with the following credentials:
Host – “localhost”, username – “root”, password – “sql@123”
Table - WORKER
ECODE NAME DESIG PLEVEL DOJ DOB
11 RADHESHYAM SUPERVISOR P001 2004-09-12 1981-08-23
15 SANYA CLERK P002 2005-12-19 1983-06-09
18 SARSA SUPERVISOR P001 2010-01-20 1982-02-01
Table - PAYLEVEL

PLEVEL PAY ALLOWANCE


P001 26000 12000
P002 22000 10000
P003 12000 6000
Complete the given Python program by filling up the blank lines to connect with
MySQL using database connectivity as directed in the questions (i) to (iv)

import mysql.connector
mycon= mysql.connector.connect(_____________________) #statement 1
cursor=mycon.cursor()
cursor.execute(_______________________) # statement 2
data=cursor.fetchall()
for row in data:
print(row)
cursor.execute(_____________________) #statement 3
mycon.__________________ #statement 4

i) Complete the statement #1 to write appropriate missing parameters.


(Use default values for the parameters)
ii) Write Statement #2 to display the NAME and PAY+ALLOWANCE for all
SUPERVISORS from the above-mentioned tables.
iii) Write Statement #3 to increase the ALLOWANCE by 1000 where the pay is greater
than 20000.
iv) Write the necessary command for statement #4 to save the updating operation.

Answers

1. mycon=ms.connect(host=”localhost”, user=”root”, passwd=”sql@123”, database=


“ADMIN”)
2. cursor.execute(“select name, pay+allowance from worker, paylevel where
worker.plevel=paylevel.plevel and desig=’supervisor’ ”)
3. cursor.execute(“update paylevel set allowance = allowance+1000 where pay>20000”)
4. mycon.commit()
4. Consider the tables Event and Celebrity are already created and available in the
database Media

Table - Event
EventId Eventname NumPerformers CelebrityID
101 Birthday 10 C102
102 Promotion Party 20 C103
103 Engagement 12 C102
104 Wedding 15 C104
105 Birthday 17 C101
Table - Celebrity
CelebrityID Name Phone FeeCharged
C101 Faiz Khan 9910195610 200000
C102 Sanjay Kumar 8934664481 250000
C103 NeeraKhan Kapoor 9811665685 300000
C104 Reena Bhatia 6587775645 100000
Complete the given Python program by filling up the blank lines to connect with
MySQL using database connectivity as directed in the questions (i) to (iv)

import mysql.connector
mycon= mysql.connector.connect(host="localhost",user="root",
passwd="admin",database="Media”)
cursor=_____________ #statement 1
cursor.execute(_______________________) # statement 2
data=___________________ # statement 3
for row in data:
print(row)
cursor.execute(_____________________) # statement 4
mycon.commit()
i) Complete the statement #1 to create the cursor object.
ii) Write Statement #2 to display the Eventname, Name of celebrity and Feecharged
for those celebrities who charge more than 200000
iii) Write Statement #3 to fetch the first 2 records from the result set.
iv) Write the necessary command for statement #4 to delete the records of the
celebrity table whose name starts with “R”.
Answers

i. cursor=mycon.cursor()
ii. cursor.execute(“select Eventname, Name, Feecharged from Event, Celebrity
where Event.CelebrityID = Celebrity. CelebrityID and feecharged > 200000”)
iii. data=cursor.fetchmany(2)+
iv. cursor.execute(“delete from Celebrity where name like ‘R%’ “)
5. Consider the tables Sports and Coach are already created and available in the
database Admin

Table - Sports
Scode Sportsname Participants Prizemoney Scheduledate
101 Carrom 2 50000 2012-01-23
103 Table Tennis 4 8000 2012-02-14
105 Chess 2 9000 2012-01-01
Table - Coach
Code Name Scode
1 Ravi 101
2 Mohan 108
3 Sameer 101

Complete the given Python program by filling up the blank lines to connect with
MySQL using database connectivity as directed in the questions (i) to (iv)

import mysql.connector as ms
mycon= ms.connect(host="localhost",user="root",passwd="1234",database="admin”)
cursor=_____________ #statement 1
cursor.execute(_______________________) # statement 2
data=___________________ # statement 3
for row in data:
print(row)
cursor.execute(_____________________) # statement 4
mycon.commit()

i) Complete the statement #1 to create the cursor object.


ii) Write Statement #2 to display details of those sports and coachname which are
having Prizemoney more than 9000.
iii) Write Statement #3 to fetch the first record from the result set.
iv) Write the necessary command for statement #4 to increase the Participants by 6 for
the sports carom, chess and badminton.

Answers

i. cursor=ms.cursor()
ii. cursor.execute(“select Sports.*,Name from Sports, Coach where
Sports.scode=Coach.scode and Prizemoney >9000”)
iii. data=cursor.fetchone()
iv. cursor.execute(“update Sports set Participants=Participants+6 where Sportsname
in (‘Carrom’, ‘Chess’, ‘badminton’)”)
6. Consider the tables Teacher and Posting are already created and available
in the database ‘School’ with the following credentials:
Host – “localhost”, username – “root”, password – “sql@123”

Table - TEACHER
T_ID NAME AGE DATE_OF_JOIN DEPT SALARY
T102 VANIPRIYA 36 10/01/2017 COMMERCE 12000
T104 JAYALAKSHMI 45 24/03/2008 ENGLISH 20000
T101 MOHAN 54 12/12/2016 PHYSICS 30000
T103 JUGAL 34 01/07/2015 COMPUTER 40000
SCIENCE

Table - POSTING
P_ID DEPT PLACE
1 HISTORY AGRA
2 MATHEMATICS RAIPUR
3 COMPUTER SCIENCE DELHI
Complete the given Python program by filling up the blank lines to connect with
MySQL using database connectivity as directed in the questions (i) to (iv)
import mysql.connector as ms
mycon= ms.connect(_____________________) #statement 1 cursor=mycon.cursor()
cursor.execute(_______________________) # statement 2
data=cursor.fetchall()
for row in data:
print(row)
cursor.execute(_____________________) # statement 3
mycon.__________________ #statement 4

i. Complete the statement #1 to write appropriate missing parameters.


(Use default values for the parameters)
ii. Write Statement #2 to display the Teacher details who have been posted in “Delhi”.
iii. Write Statement #3 to increase the salary for the teachers by 10% who have joined
during the year 2017 and 2018.
iv. Write the necessary command for statement #4 to save the updating operation.
Answers:

i. mycon=ms.connect(host=”localhost”, user=”root”, passwd=”sql@123”, database=


“School”)
ii. cursor.execute(“Select * from Teacher, Posting where Teacher.Dept=Posting.Dept
and place=’Delhi’ “)
iii. cursor.execute(“Update Teacher set Salary=Salary+.1*Salary where date_of_join
between ‘2017-01-01’ and ‘2018-12-31’
iv. mycon.commit()
7. Consider the tables Student and Stucontact are already created and available in the
database School

Table - Student
ADMNO SNAME GENDER DOB STREAM FEES
JC1234 KAMAL MALE 2000-09-09 SCIENCE 45000
JC1324 SUPRIYA FEMALE 2001-08-07 COMMERCE 40000
JC3456 VARAHAN MALE 2002-07-06 SCIENCE 45000
Table - Stucontact

ADMNO FNAME MNAME ADDRESS


JC1234 RAJA RANI NATESAN ST
JC1324 SHIVAKUMAR PARVATHI SECOND ST
JC2345 SANGEETHA DEVARAYAN ST

Complete the given Python program by filling up the blank lines to connect with
MySQL using database connectivity as directed in the questions (i) to (iv)
import mysql.connector as ms
mycon= ms.connect(host="localhost",user="root",passwd="1234",database="school”)
cursor=_____________ #statement 1
cursor.execute(_______________________) # statement 2
data=___________________ # statement 3
for row in data:
print(row)
cursor.execute(_____________________) # statement 4
mycon.commit()

i) Complete the statement #1 to create the cursor object.


ii) Write Statement #2 to display the student name, Father name and mother name of female
students.
iii) Write Statement #3 to fetch the records from the result set.
iv) Write the necessary command for statement #4 to delete the records of the student

Answers:
i. cursor=mycon.cursor()
ii. cursor.execute(“Select Sname, Fname, Mname from Student, Stucontact where
Student.admno=Stucontact.admno and gender=’Female’ “)
iii. data=cursor.fetchall()
iv. cursor.execute(“Delete from Student”)

You might also like