Thursday, December 20, 2012

SQL tests

Example data 1:
==============================
|FirstName      |LastName    |
==============================
|'Peter'        |'Hansen'    |
|'Peter'        |'Jackson'   |
|'John'         |'Nilsen'    |
|'David'        |'Jackson'   |
==============================


Question 1: Lets have Example data 1;
How much rows will return this query:

SELECT * FROM Persons A, Persons B WHERE
(A.FirstName = B.FirstName Or  A.LastName = B.LastName) AND NOT
(A.FirstName = B.FirstName AND A.LastName = B.LastName)


Question 2: Sub-queries can be nested in which queries? SELECT? UPDATE? ...

Question 3: Usage of IN keyword

Question 4: How could you delete rows? DELETE? REMOVE? DROP?
DELETE FROM Persons WHERE FirstName = 'Peter'

Question 5: Example data 1.
How many records will output the following statement:

SELECT * FROM Persons A LEFT OUTER JOIN Persons B ON (A.LastName = B.LastName) WHERE A.FirstName = ‘Peter’

Question 6: Example data 1.
How many records will output the following statement:

SELECT FirstName, LastName FROM Persons WHERE LastName > ‘Hansen’

Question 7: Which of the following is a SQL aggregate function?
  1. CAST
  2. LEFT
  3. MIN
  4. RIGHT

Question 8: Which SQL statement is used to extract data from a database?
  1. EXTRACT
  2. GET
  3. OPEN
  4. SELECT

Question 8: Which SQL statement is used to delete data from a database?
COLLAPSE
DELETE
REMOVE
VACUUM
   
Question 9: If you don't specify ASC or DESC after a SQL ORDER BY clause, the following is used by default.
  1. ASC
  2. DESC
  3. Random
  4. There is no default value.


Question 10: Which of the following SQL statements is correct?
Strictly speaking, some databases will allow you to run any of the given statements, but only one of them is logically correct and will not cause error on any SQL database server/engine.
SELECT CustomerName, COUNT(CustomerName) FROM Orders
SELECT CustomerName, COUNT(CustomerName) FROM Orders GROUP BY CustomerName
SELECT CustomerName, COUNT(CustomerName) FROM Orders ORDER BY CustomerName
  
Question 11: A trigger belongs to…
  1. a single table in the database
  2. more than one table in the database
  3. to all tables in the database


Question 12: Example data 1.
How many records will output the following statement:

SELECT * FROM Persons GROUP BY FirstName, LastName

2
3
4
5
  
Question 13: Example data 1.
How many records will output the following statement:

SELECT * FROM Persons GROUP BY FirstName, LastName

Question 14: Which of the following is a SQL aggregate function?
  1. AVG
  2. JOIN
  3. LEFT
  4. LEN

Question 15: What is a trigger?
 A trigger defines relations between tables.
A trigger is a special kind of stored procedures executed when certain event occurs.
A trigger is part of data extraction process.

Question 16: BETWEEN syntax:
SELECT *
FROM suppliers
WHERE supplier_id BETWEEN 5000 AND 5010;


Question 17: sql subqueries http://www.tizag.com/sqlTutorial/sqlsubqueries.php

Question 18: Describe EXTRACT function.
The EXTRACT() function is used to return a single part of a date/time, such as year, month, day, hour, minute, etc.

Example:
SELECT EXTRACT(YEAR FROM OrderDate) AS OrderYear,
EXTRACT(MONTH FROM OrderDate) AS OrderMonth,
EXTRACT(DAY FROM OrderDate) AS OrderDay,
FROM Orders
WHERE OrderId=1





http://www.academictutorials.com/quiz.asp?id=19 - site with many tests







No comments:

Post a Comment