SQL Test

Tests knowledge of SQL database queries, statements, operators, and functions including DCL statements, aggregate functions, subqueries, joins, and SELECT statement evaluation order.

15 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following is not a Data Control Language (DCL) statement?

  1. COMMIT
  2. ROLLBACK
  3. LOCK TABLE
  4. SAVEPOINT
  5. SET TRANSACTION
Question 2 Multiple Choice (Single Answer)

What does the following query do?
SELECT * from Employee WHERE SALARY LIKE '_2%3'

  1. Finds any values that end with 2
  2. Finds any values that start with 2 and are at least 3 characters in length
  3. Finds any values in a five-digit number that start with 2 and end with 3
  4. Finds any values that have 2 in the second position and end with 3
  5. None of these
Question 3 Multiple Choice (Single Answer)

Which of the following is not true about aggregate functions?

  1. MAX and MIN functions work on numeric and non-numeric data.
  2. SUM and AVERAGE work on numeric data.
  3. Aggregate functions do not work on complex mathematical expressions like log, square root, etc.
  4. SUM and AVERAGE work on non-numeric data.
  5. There is no influence of distinct keywords in aggregate function.
Question 4 Multiple Choice (Single Answer)

Which of the following complex expressions is not allowed in SQL?

  1. LOG(marks)*√total
  2. MIN(Col1+col2)
  3. SUM(marks)/COUNT(marks)
  4. AVG(marks)
  5. COUNT(*)
Question 5 Multiple Choice (Single Answer)

What will be the conceptual order of evaluation of the following select statements?
(a) First, the Cartesian product of all tables in the 'form' clause is formed.
(b) From this, rows not satisfying the 'where' condition are eliminated.
(c) Groups not satisfying the having clause are then eliminated.
(d) The remaining rows are grouped in accordance with 'group by' clause.
(e) The UNION, INTERSECT, EXCEPT is taken after each subquery is evaluated.
(f) If the keyword DISTINCT is present, duplicate rows are eliminated.
(g) The expressions of the select clause target list are evaluated.
(h) The set of all selected rows is sorted if an ORDER BY is present.

  1. a - b - c - d - e - f - g - h
  2. a - b - d - c - g - f - e - h
  3. a - b - d - h - c - g - f - e
  4. a - b - e - g - f - c - d - h
  5. none of these
Question 6 Multiple Choice (Single Answer)

Alter command is used:
(a) to delete a column in a table
(b) to change the data type of a column in a table
(c) to add a column in a table
(d) to rename a table

  1. only a
  2. a and b
  3. a, b and c
  4. all of these
  5. none of these
Question 7 Multiple Choice (Single Answer)

Which of the following is not a difference between EXISTS and ANY/ALL?

  1. EXISTS is more powerful than ANY/ALL.
  2. All queries represented by ANY/ALL can be obtained by EXISTS operator.
  3. All queries represented by EXISTS may not be possible with ANY/ALL operator.
  4. ALL returns TRUE only if all the results of a subquery meet the condition, while EXISTS takes a subquery as an argument and returns TRUE if the subquery returns anything.
  5. Replacing EXISTS with ANY produces an identical result.
Question 8 Multiple Choice (Single Answer)

Which of the following is/are correct syntax(es) for insert statement?
(a) INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)] VALUES (value1, value2, value3,...valueN);
(b) INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);
(c) INSERT INTO CUSTOMER (column1,column5,columnN-1)VALUES (value1,value5,valueN-1);

  1. a and b
  2. a, b and c
  3. only a
  4. only b
  5. none of these
Question 9 Multiple Choice (Single Answer)

What will be the output of the following query?
Select sum(price) from room r where roomno not in(select roomno from booking b, hotel h where(datefrom<=current_date and dateto>=current_date)and b. hotelno=h.hotelno and hotelname='XYZ')

Hotel(hotelno, hotelname, city) Room(roomno, hotelno, type, price) Booking(hotelno, guestno, datefrom, dateto, roomno) Guest(gustno, guestname, guestadd)

  1. Total revenue/expenditure lost from unoccupied room of XYZ hotel in a specific period
  2. Total revenue/expenditure lost from unoccupied room of XYZ hotel as on date
  3. Total revenue/expenditure lost from occupied room of XYZ hotel as on date
  4. Total revenue/expenditure gained from occupied room of XYZ hotel as on date
  5. None of these
Question 10 Multiple Choice (Single Answer)

Which of the following is/are the difference(s) between having and where clause?
(a) Where is used to filter rows while having is used to filter groups.
(b) There is no alternative for 'where'. To filter groups, we have operators other than 'having'.
(c) Aggregate cannot be used in where clause. Aggregate can be used in having clause.

  1. Only a
  2. Both a and b
  3. All a, b and c
  4. Both b and c
  5. None of these
Question 11 Multiple Choice (Single Answer)

Which of the following explains 'correlated subquery'?

  1. Query evaluated once for every row processed by the parent statement
  2. Query evaluated once for the entire parent statement
  3. Query that retrieves multiple columns but single row
  4. Query displaying one column and one row
  5. Query which retrieves multiple columns and multiple rows
Question 12 Multiple Choice (Single Answer)

What will be the output of the following query?
select count(*) from employees e1, e2, department d where e1.lname='abc , e1.fname='xyz', e1.empid=d.mgrempid and d.dptno=e2.dptno.
Tables:
Employee(empid,fname,lname,add,dob,position,deptno)
Dpartment(deptno,deptname,mgrempid)
Project(projno,projname,deptno)
Workson(empid,projno,hoursworked)

  1. It finds out how many employees are managed by 'xyz abc'.
  2. It finds the list of employees that are managed by 'xyz abc'.
  3. It counts the number of managers bearing the name 'xyz abc'
  4. It finds out the managers bearing the name 'xyz abc'
  5. None of these
Question 13 Multiple Choice (Single Answer)

What will be the result of the following query?

Select title_id,copies_sold=sum(qty) from sales where ord_date between '1/1/2010 and '12/31/2010' group by all title_id
Sales(title_id,qty,ord_date)

  1. All the title id's and quantity of books sold
  2. All the title id's and total quantity sold
  3. Total quantity of books that were sold during the year 2010
  4. All the title id's and quantity of books sold during the year 2010
  5. None of these
Question 14 Multiple Choice (Single Answer)

What does the following select statement do?
Select fname,lname from employees where exists (select * from dependent where ssn=essn) and exists (select * from department where ssn=mgrssn);

Consider Table: Employee(fname,minit,lname,ssn,bdate,add,salary,dno)
Department(dmname,dno,mgrssn,mgrstartdate)
Work_on(essn,pno,hours)
Project(pname,pno,plocation,dno)
Dept_locations(dno,dlocation)

  1. Lists the names of all the employees who have managers
  2. Lists the names of all the managers who have dependents
  3. Lists the names of managers who have at least one dependent
  4. Lists the names of employees with at least one dependent
  5. None of these
Question 15 Multiple Choice (Single Answer)

What would be the query for enlisting the faculty member who does not teach any class using outer join?

Tables: Faculty(facid,facname,......) Student(stuid,stuname,.......) Class(facid,course,.......)

  1. select f.facid, f.facname from class c,faculty f where c.facid(+)=f.facid and c.course is null order by f.facname;
  2. select f.facid, f.facname from class c right join faculty f on c.facid(+)=f.facid where c.course is null order by f.facname;
  3. select f.facid, f.facname from class c,faculty f where c.facid(+)=f.facid(+) and c.course is null order by f.facname;
  4. select f.facid, f.facname from class c full join faculty f on c.facid=f.facid where c.course is null order by f.facname;
  5. all of the above