sp-1 FINAL
sp-1 FINAL
(1)
a)COUNT()
b)NUMBER()
c)SUM()
d)COUNT(*)
2. Which of the following SQL clauses is used to DELETE tuples from a database table? (1)
a)DELETE
b)REMOVE
c)DROP
d)CLEAR
3.________________ is not a category of SQL command. (1)
a)TCL
b)SCL
c)DML
d)DDL
6. With SQL, how do you select all the records from a table named “Persons” where the value of
the column “FirstName” ends with an “a” ? (1)
a) SELECT * FROM Persons WHERE FirstName=’a’
b) SELECT * FROM Persons WHERE FirstName LIKE ‘a%’
c) SELECT * FROM Persons WHERE FirstName LIKE ‘%a’
d) SELECT * FROM Persons WHERE FirstName=’%a%’
7. With SQL, how can you return the number of not null records in the “Persons” table? (1)
a) SELECT COUNT() FROM Persons
b) SELECT COLUMNS() FROM Persons
c) SELECT COLUMNS(*) FROM Persons
d) SELECT COUNT(*) FROM Persons
9. How can you change “Hansen” into “Nilsen” in the “LastName” column in the Persons table?
(1)
a) UPDATE Persons SET LastName=’Hansen’ INTO LastName=’Nilsen’
b) MODIFY Persons SET LastName=’Nilsen’ WHERE LastName=’Hansen’
c) MODIFY Persons SET LastName=’Hansen’ INTO LastName=’Nilsen’
d) UPDATE Persons SET LastName=’Nilsen’ WHERE LastName=’Hansen’
11. Find all the cities with temperature, condition and humidity whose humidity is in the range
of 63 to 79. (1)
a) SELECT * FROM weather WHERE humidity IN (63 to 79)
b) SELECT * FROM weather WHERE humidity NOT IN (63 AND 79)
c) SELECT * FROM weather WHERE humidity BETWEEN 63 AND 79
d) SELECT * FROM weather WHERE humidity NOT BETWEEN 63 AND 79
12. The command to remove rows from a table ‘CUSTOMER’ is (1)
a) DROP FROM CUSTOMER
b) UPDATE FROM CUSTOMER
c) REMOVE FROM CUSTOMER
d) DELETE FROM CUSTOMER WHERE
13. Find the name of those cities with temperature and condition whose condition is either
sunny or cloudy but temperature must be greater than 70. (1)
a) SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ AND
condition = ‘cloudy’ OR temperature > 70
b) SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ OR
condition = ‘cloudy’ OR temperature > 70
c) SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ OR
condition = ‘cloudy’ AND temperature > 70
d) SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ AND
condition = ‘cloudy’ AND temperature > 70
14. Find all the tuples having temperature greater than ‘Paris’.(Hint: The following are nested
queries). (1)
a) SELECT * FROM weather WHERE temperature > (SELECT temperature FROM weather
WHERE city = ‘Paris’
b) SELECT * FROM weather WHERE temperature > (SELECT * FROM weather WHERE city
= ‘Paris’)
c) SELECT * FROM weather WHERE temperature > (SELECT city FROM weather WHERE
city = ‘Paris’)
d) SELECT * FROM weather WHERE temperature > ‘Paris’ temperature
16.What is the Django shortcut method to more easily render an html response? (1)
19. The following query belongs to which category of mysql query. (1)
x=96
21. Consider the tables ITEMS & COMPANY. Write SQL commands for query for (i) and
output for (ii) (2)
Table: ITEMS
ID PNAME PRICE MDATE QTY
T001 Soap 12.00 11/03/2007 200
T002 Paste 39.50 23/12/2006 55
T003 Deodorant 125.00 12/06/2007 46
T004 Hair Oil 28.75 25/09/2007 325
T005 Cold Cream 66.00 09/10/2007 144
T006 Tooth Brush 25.00 17/02/2006 455
Table : COMPANY
ID COMPANYNAME City
T001 HLL Mumbai
T008 Colgate Delhi
T003 HLL Mumbai
T004 Paras Haryana
i). To display product name, company name & price for those items which IDs
are equal to the IDs of company.
ii . SELECT COUNT(*) FROM ITEMS WHERE ITEMS.ID=COMPANY.ID;
22. Write MySql commands for (i) to (vi) based on the following table. (3)
Table: SUPPLIERS
SCODE SNAME CITY STATE AMOUNT
1001 RAJESH BHIKHIWIND PUNJAB 5000
1002 RAJAT AMRITSAR PUNJAB 5400
1003 PUNEET SONIPAT HARYANA 6200
1004 RACHNA FARIDABAD HARYANA 8400
1005 RAMAN JAMUNANAGAR HARYANA 8940
1006 PRAGTI BISHRAMPUR CHATTISGARH 4800
1007 PRAHAL BABRALA UTTER 3000
AD PARDESH
1008 KOCHER LAKHERI RAJASTHAN 2500
23. On the basis of following table answer the given questions: (3)
Table: CUSTOMER_DETAILS
(ii)What will be the output of the following query :Select max(DOJ) From Customer_Details;
(iii)Write the sql query to delete the row from the table where customer has no accumulated
amount.
24. Write commands in SQL for (i) to (iv) and output for (v) and (vi). (3)
Table : Store
(i)To display names of stores along with SalesAmount of those stores that have ‘fashion’
anywhere in their store names.
(ii)To display Stores names, Location and DateOfOpen of stores that were opened before 1st
March, 2015.
(iii)To display name and location of those store which have either ‘u’ as second character in their
name.
(iv)To display the City and the number of stores located in that City, only if number of stores is
more than 2.
26. In a school, a database named “school” is created in mysql whose password is “cbse”. Smith
is trying to add a new record of a student having details(3,’michelle’,’agartala’) in a ‘student’
table.Write the code in python to read the contents of ‘number.csv’ file consisting of data from a
mysql table and print the data of the table on the screen in tabular form of the table. (4)
27. Write a python program that deletes the last row from the above created ‘student’ table of
mysql database ‘school’. Write a python program that displays first five rows fetched from
‘student’ table of mysql database ‘school’. (4)
28. Identify primary key, candidate key and alternate key from the following table and explain
those keys in detail. (4)
R.No Name Stipend Stream AvgMark Grade Class
101 Neha 450 Medical 89.2 A 11C
102 Damini 400 Commerce NULL B 12B
103 Gaurav 250 Humanities 64.4 C 11A
104 Anu 300 Commerce 67.5 C 12B
105 Vikas 500 Non-Medical 92 A 12A
106 Rubina 450 Non-Medical 88.5 A 12A
1) Display all the names of all students who are in Medical Stream.
2) To display name and average of all the students having AvgMark < 70.0.
3) To display the list of all the students with stipend > 350.00 in ascending order of Name.
4) To display the student details with Name, Marks for each student in the table. Marks are
calculated as AvgMark * 5;
5) To insert a new record in the table student with the following data.
7,’Radhika’,500.00,’commerce’,90.8,’A’,’12A’.
6) To display the list of all the students whose names ends with a character ‘a’.
7) To display the list in descending order of AvgMark.
8) To delete the rows of C grade.
31. Create the table SHOP with the suitable datatype for the below given information. (4)
Table Name : Shop
No Shopname Sale Area Cust_Percent Rating City
1 S.M.Sons 2500000 West 68.6 C Delhi
2 Dharohar 5000000 South 81.8 A Mumbai
3 Kriti Art 3000000 North 79.8 B Kolkata
4 Ripple 3800000 North 88 B Mumbai
5 Biswast stores 4560000 East 92 A Delhi
6 Crystal 2900000 South 66.7 A Kolkata
a) Display the names of all shops which are in the area south.
b) To display Name and customer Percentage of all the shops having cust_percent > 80.
c) To display the list of all the shops with sale > 300000 in ascending order of shop name.
d) To display a report with shopname, Area and Rating for each shop in the table, for only
those shops where sale is between 350000 and 400000. (Including both 350000 and
400000).
e) To display the distinct city.
f) To update the customer percent by 5% of south area.
g) To display the list in descending order of sale.
h) To delete all the rows where sale in less than 400000.
32. Consider the following table-EMP and write the outputs for the Q.No.(a) to Q.No.(j) and
write queries for (ix) and (x). (5)
EMP ENAME JOB MGRN HIREDATE SALAR COM DEPT
NO O Y M NO
7369 Sunita Clerk 7902 1990-12-17 12800 Null 20
7499 Asho Salesman 7698 1991-02-20 13600 1300 30
7521 Sumit Salesman 7698 1991-02-22 15250 1500 30
7566 Jyoti Manager 7839 1991-04-02 14975 Null 20
7654 Martin Salesman 7698 1991-09-28 16250 2400 30
7698 Binod Manager 7839 1991-05-01 15850 Null 30
7782 Chetan Manager 7839 1991-04-19 12450 Null 10
7788 Sudhir Analyst 7566 1997-04-19 15000 Null 20
7839 Kavita President Null 1991-11-17 19000 Null 10
7844 Tushar Salesman 7698 1991-09-08 14500 0 30
7876 Anand Clerk 7788 1997-05-23 16100 Null 20
7900 Jagdeep Clerk 7698 1991-12-03 14900 Null 30
7902 Sumit Analyst 7566 1991-12-03 13500 3600 20
7934 Manoj Clerk 7782 1992-01-03 15300 Null 10
i) SELECT COUNT(*) FROM EMP WHERE DEPTNO=20;
ii) SELECT SUM(COMM) FROM EMP WHERE DEPTNO=30;
iii) SELECT MIN(SAL) FROM EMP WHERE DEPTNO=10;
iv) SELECT AVG(COMM) FROM EMP WHERE COMM<1500;
v) SELECT COUNT(DISTINCT JOB) FROM EMP;
vi) SELECT SUM(SALARY+COMM) FROM EMP WHERE JOB=”MANAGER’;
vii) SELECT CONCAT(ENAME, JOB) FROM EMP WHERE JOB=’ANALYST’;
viii) SELECT MAX(SALARY) FROM EMP WHERE COMM IS NULL;
ix) To display ename,job,salary, hiredate of employees who are hired between May 20,
1990 and December 31, 1991. Order the query in ascending order of the Hiredate.
x) To display all details of the job of post clerk, analyst or manager.
33. You need to display a webpage news.html in response to URL<server>/about/work/ for app
work in your Django project named Headlines. Write the following: (4)