Wor ch2 SQL (QN Only)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Ch 2: SQL

QN QUESTION
O
1 What are DDL and DML? Give one command of each.
2 Which command is used to add new column in existing table?
3 Which clause is used to search for NULL values in any column?
4 Which command is used to see information like name of columns, data type, size etc. ?
5 Which clause is used for pattern matching? What are the 2 main characters used for matching
the pattern?
6 Which clause is used to see the output of query in ascending or descending order?
7 Which clause is used to eliminate the duplicate rows from output?
8 What is the minimum number of column required in MySQL to create table?
9 Which command is used to remove the table from database?
10 Which command is used to add new record in table?
11 Which option of ORDER BY clause is used to arrange the output in descending order?
12 Which command is used to change the existing information of table?
13 Raj is a database programmer, He has to write the query from EMPLOYEE table to
search for the employee whose name begins from letter „R‟, for this he has written the
query as: SELECT * FROM EMPLOYEE WHERE NAME=‟R%‟;
But the query is not producing the correct output, help Raj and correct the query so that he
gets the desired output.
14 Raj is a database programmer, He has to write the query from EMPLOYEE table to
search for the employee who are not getting any commission, for this he has written the
query as: SELECT * FROM EMPLOYEE WHERE commission=null;
But the query is not producing the correct output, help Raj and correct the query so that
he gets the desired output.
15 Raj is a database programmer, has to write the query from EMPLOYEE table to search for
the employee who are working in „Sales‟ or „IT‟ department, for this he has written the
query as: SELECT * FROM EMPLOYEE WHERE department=‟Sales‟ or „IT‟;
But the query is not producing the correct output, help Raj and correct the query so that he
gets the desired output.
16 The following query is producing an error. Identify the error and also write the correct query.
SELECT * FROM EMP ORDER BY NAME WHERE SALARY>=5000;
17 If Table Sales contains 5 records and Raj executed the following queries; find out the
output of both the query.
(i) Select 100+200 from dual;
Select 100+200 from Sales;
18 What is the difference between Equi-Join and Natural Join?
19

20 Which SQL function is used to get the average value of any column?
21 What is the difference between COUNT() and COUNT(*) function
22 What is the full form of SQL?
23 Query to delete all record of table without deleting the table:
a. DELETE TABLE TABLE_NAME
b. DELETE FROM TABLE_NAME
c. DROP TABLE TABLE_NAME
DELETE TABLE FROM TABLE_NAME
24 Identify the wrong statement about UPDATE command
a. If WHERE clause is missing all the record in table will be updated
b. Only one record can be updated at a time using WHERE clause
c. Multiple records can be updated at a time using WHERE clause
None of the above
25 Identify the correct statement(s) to drop a column from table
a. DELETE COLUMN COLUMN_NAME
b. DROP COLUMN COLUMN_NAME
c. ALTER TABLE TABLE_NAME DROP COLUMN COLUMN_NAME
ALTER TABLE TABLE_NAME DROP COLUMN_NAME
26 Suppose a table BOOK contain columns (BNO, BNAME, AUTHOR, PUBLISHER), Raj is
assigned a task to see the list of publishers, when he executed the query as:
SELECT PUBLISHER FROM BOOK;
He noticed that the same publisher name is repeated in query output. What could be
possible solution to get publisher name uniquely? Rewrite the following query to fetch
unique publisher names from table.
27 HOTS
Consider a database table T containing two columns X and Y each of type integer. After
the creation of the table, one record (X=1, Y=1) is inserted in the table.
Let MX and MY denote the respective maximum values of X and Y among all records in
the table at any point in time. Using MX and MY, new records are inserted in the table
128 times with X and Y values being MX+1, 2*MY+1 respectively. It may be noted that
each time after the insertion, values of MX and MY change. What will be the output of
the following SQL query after the steps mentioned above are carried out?
SELECT Y FROM T WHERE
X = 7 A. 127
B. 255
C. 129
D. 257
28 Which SQL function is used to find the highest and lowest value of numeric and date type
column?
29
What is the default order of sorting using ORDER BY?
30
What is the difference between CHAR and VARCHAR?
31

(i) To display details of all transactions of TYPE Withdraw from TRANSACT table
(ii) To display ANO and AMOUNT of all Deposit and Withdrawals done in month of
„May‟ 2017 from table TRANSACT
(iii) To display first date of transaction (DOT) from table TRANSACT for Account
having ANO as 102
(iv) To display ANO, ANAME, AMOUNT and DOT of those persons from
ACCOUNT and TRANSACT table who have done transaction less than or
equal to 3000
(v) SELECT ANO, ANAME FROM ACCOUNT
WHERE ADDRESS NOT IN ('CHENNAI', 'BANGALORE');
(vi) SELECT DISTINCT ANO FROM TRANSACT
(vii) SELECT ANO, COUNT(*), MIN(AMOUNT) FROM
TRANSACT GROUP BY ANO HAVING COUNT(*)> 1
(viii) SELECT COUNT(*), SUM(AMOUNT) FROM
TRANSACT WHERE DOT <= '2017-10-01'
32

33
(i) To display details of all Trains which starts from New Delhi
(ii) To display PNR, PNAME, GENDER and AGE of all passengers whose AGE is
below 50
(iii) To display total numbers of MALE and FEMALE passengers
(iv) To display records of all passengers travelling in trains whose TNO is 12015
(v) SELECT MAX(TRAVELDATE),MIN(TRAVELDATE) FROM PASSENGERS
WHERE GENDER=‟FEMALE‟;
(vi) SELECT END, COUNT(*) FROM TRAINS GROUP BY END HAVING COUNT(*)>1;
(vii) SELECT DISTINCT TRAVELDATE FROM PASSENGERS;
(viii) SELECT TNAME, PNAME FROM TRAINS T, PASSENGERS P WHERE
T.TNO=P.TNO AND AGE BETWEEN 50 AND 60
34

(i) To display Name and Price of all the Accessories in descending order of their Price
(ii) To display Id and Sname of all the Shoppe location in „Nehru Place‟
(iii) To display Name, Minimum and Maximum Price of each Name from
ACCESSORIES table
(iv) To display Name, Price of all Accessories and their respective SName from table
SHOPPE and ACCESSORIES where Price is 5000 or more.
(v) To display all details of accessories where name contains word „Board‟;
(vi) SELECT DISTINCT NAME FROM ACCESSORIES WHERE PRICE>5000;
(vii) SELECT AREA,COUNT(*) FROM SHOPPE GROUP BY AREA;
(viii) SELECT AVG(PRICE), MAX(PRICE) FROM ACCESSORIES WHERE PRICE>=10000;
(ix) SELECT NAME, PRICE*.05 DISCOUNT FROM ACCESSORIES WHERE ID IN
(„S02‟,‟S03‟)
(x) SELECT * FROM SHOPPE S, ACCESSORIES A WHERE S.ID = A.ID AND
PRICE>=10000;
35

(i) To display ICode, IName and VName of all the vendors, who manufacture “Refrigerator”.
(ii) To display IName, ICode, VName and price of all the products whose price >=23000
(iii) To display Vname and IName manufactured by vendor whose code is “P04”.
36

(i) To display PatNo, PatName and corresponding DocName for each patient.
(ii) To display the list of all doctors whose NoofOpdDays are more than 3
(iii) To display DocName, Department,PatName and DocId from both the tables where
DocID is either 101 or 103
(iv) To display total no of different departments from Patients table.
37

38 Rajesh a database developer at StoreIndia wants to search the record of those employees
whose name starts from „R‟ and they have not allotted any project, for this he has
written the following query-
Select * from Employee where Name = ‘R%’ and Project=Null;
But the query is not producing the correct output. Rewrite the query after correcting the
errors
39

(i) Write a query to display VisitorName, Coming From details of Female Visitors
with Amount Paid more than 3000
(ii) Write a query to display all coming from location uniquely
(iii) Write a query to insert the following
values- 7,
„Shilpa‟,‟F‟,‟Lucknow‟,3000
(iv) Write a query to display all details of visitors in order of their AmountPaid from
highest to lowest
(v) Select VisitorName from Visitor where Gender=‟M‟;
(vi) Select AmountPaid+200 from Visitor where VisitorID=6;
(vii) Select Sum(AmountPaid) from Visitor where comingFrom=‟Kanpur‟;
(viii) Select Count(VisitorName) from Visitor where AmountPaid is NULL;
40

41
What is the Difference between ALTER Table command and UPDATE command?
42 (i) Sanjay was deleting the record of empno=1234, but at the time of execution of
command he forgot to add condition empno=1234, what will be the effect of delete
command in this case?
(ii) Sameer is executing the query to fetch the records of employee who are getting
salary between 4000 to 8000, he executed the query as -
Select * from employee where salary between 4000 to 8000; But he is not getting the
correct output, Rewrite the correct query.
43
Write MYSQL command to see the list of tables in current database
44
Sunil decides to delete a PhoneNo column from a MySQL Table (student) after insert the
data into the table. Write the command to delete that particular column in student table.
45 A table Employee contains 5 Rows and 4 Columns and another table PROJECT
contains 5 Rows and 3 Columns. How many rows and columns will be there if we
obtain Cartesian product of these two tables?
46 Ranjeet created a table named student, He wants to see those students whose name
ending with p. He wrote a query- SELECT * FROM student WHERE name=”p%”;
But the query is not producing the desired output, Help Ranjeet to run the query by
removing the errors from the query and rewriting it.
(i) To display the name of employees starting from „V‟ in ascending order of their
salary
(ii) To display the details of all SALES dept employee who are earning salary more
than 20000
(iii) To count distinct department from the table
(iv) Change the salary of NITIN from 18000 to 20000
(v) To insert a new row in the table Employee
„6‟, „SUMIT‟,‟HR‟, 40000,2000
(vi) Select AVG(COMM) from Employee
(vii) Select ENAME,DEPT from Employee where Dept in(„HR‟,‟ACCOUNTS‟)
(viii) Select ENAME, SALARY+100 NEWSAL from Employee
47

48

Write the MySQL queries for the following :


(i) To display PatID, PatName, and corresponding DocName of „Cardio‟ and
„Ortho‟ patient
(ii) To display DocName, PatName of those patient who are admitted before 15-
Oct- 2013
49

1. TO DISPLAY THE NAME OF STUDENT , SUBJECT AND ADVISOR NAME


2. TO DISPLAY THE STUDENT NAME AND ADVISOR ALL THE STUDENTS WHO ARE
OFFERING EITHER PHYSICS OR CHEMISTRY
50 DIFFERENCE BETWEEN
1. HAVING AND WHERE
2. % AND _
3. CHAR AND VARCHAR

You might also like