Preview

06 - SQL Part 1

 1. SQL stands for ________________________________
SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the International Organization for Standardization (ISO) in 198

  Standad Query Language

  Social Query Luger

  Structured Query Language

  Standard Question Lobber

 2. SQL is a standard language for ______________________________ data in databases.

  selling

  storing, manipulating and retrieving

  following

  automatically deleting

 3. Which of the following statements about SQL are true?
SQL can execute queries against a database
SQL can retrieve data from a database
SQL can insert records in a database
SQL can update records in a database
SQL can delete records from a database
SQL can create new databases
SQL can create new tables in a database
SQL can create stored procedures in a database
SQL can create views in a database
SQL can set permissions on tables, procedures, and views

  All of them

  1,2,3 and 5

  None of them

  Only the last four on the list

 4. SQL keywords are NOT case sensitive: select is the same as SELECT

  TRUE

  FALSE

 5. Fill in the blanks for the following list that describes some common SQL commands
SELECT - extracts data from a database
UPDATE - updates data in a database
DELETE - deletes data from a database
INSERT INTO - inserts new data into a database
CREATE DATABASE - creates a new database
ALTER DATABASE - modifies a database
CREATE TABLE - creates a new table
ALTER TABLE - modifies a table
DROP TABLE - deletes a table
CREATE INDEX - creates an index (search key)
DROP INDEX - __________________

  deletes an index

  allows drag and drop capability on an index

  modifies an index

  None of these options are correct

 6. The SELECT statement is used to select data from a database. The data returned is stored in a result table, called the result-set.

  FALSE

  TRUE

 7. Here, column1, column2, ... are the field names of the table you want to select data from. If you want to select all the fields available in the table, use the following syntax:
SELECT column1, column2, ...
FROM table_name;

  SELECT table_name *from *

  SELECT * FROM table_name;

  SELECT * from *

  SELECT FROM **

 8. Below is a selection from the "Customers" table in the Northwind sample database. What does the following SQL statement do?
SELECT CustomerName, City FROM Customers;
northwind_db_1.png

  Selects the name of the City, for each Customer, from the table

  Selects all the Customers from the Customer's table

  Selects the Customers from the City field

  Selects the "CustomerName" and "City" columns from the "Customers" table

 9. The following SQL statement deletes all the columns from the "Customers" table
SELECT * FROM Customers;

  TRUE

  FALSE

 10. Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values. You could use:

  the SELECT DISTINCT statement

  the SELECT FORMAT statement

  the SELECT * statement

  the SELECT ** statement

 11. What does the following SQL statement do?
SELECT Country FROM Customers;

  It selects the "Country" column and inserts it into the "Customers" column

  It selects only the duplicate values from the "Country" column as well as from the "Name" column

  It selects all (and duplicate) values from the "Customers" column in the "Country" table

  It selects all (and duplicate) values from the "Country" column in the "Customers" table

 12. What does the following SQL statement do?
SELECT * FROM Customers
WHERE city ='London';

  It selects the first five (by default) customers from the city "London" in the "Customers" table

  It selects all the columns and returns the city only, if the city="London"

  It selects a single customer from the city "London" from the "Customers" table

  It selects all the customers from the city "London", in the "Customers" table

 13. SQL requires single quotes around text values (most database systems will also allow double quotes). However, numeric fields should not be enclosed in quotes:
SELECT * FROM Customers
WHERE CustomerID=1;

  FALSE

  TRUE

 14. The following operators can be used in the WHERE clause. Can you fill in the blanks for the last one?
Operator	Description
=============================

=	Equal
<>	Not equal. or written as !=
>	Greater than
<	Less than
>=	Greater than or equal
<=	Less than or equal
BETWEEN	Between a certain range
IN	To specify multiple possible values for a column
LIKE	________________________?

  searches for columns that are similar to a searched for column and deletes it

  searches for single letters or numbers in a table name

  searches for the word "LIKE"

  searches for a pattern

 15. The WHERE clause can be combined with AND, OR, and NOT operators. The AND operator displays a record if just one of the conditions separated by AND are TRUE.

  TRUE

  FALSE

 16. What SQL statement selects all fields from "Customers" where country is NOT "Germany"?
Answer 1
========

SELECT NOT FROM Customers
WHERE * Country='Germany';



Answer 2
========

SELECT * FROM Customers
WHERE NOT Country='Germany';



Answer 3
========

SELECT * FROM Customers
WHERE Country= NOT 'Germany';

  None of these answers are valid

  Answer 3

  Answer 1

  Answer 2

 17. Which SQL statement selects all fields from "Customers" where country is "United Kingdom" AND city must be "London" OR "Manchester"?
Answer 1
=========

SELECT * FROM Customers
WHERE Country='United Kingdom' AND (City='London' OR City='Manchester');

Answer 2
=========

SELECT * FROM Customers
WHERE Country AND City OR City = "United Kingdom", "London", "Manchester";


Answer 3
=========

SELECT * FROM Customers
WHERE Country='United Kingdom' OR (City='London' AND City='Manchester');

  Answer 2

  None of these answers are valid

  Answer 1

  Answer 3

 18. This is the correct syntax (note carefully the position of the 'NOT') for selecting all fields where the country is NOT 'Germany' and also NOT 'USA'
SELECT * FROM Customers
WHERE Country= NOT 'Germany' AND Country= NOT 'USA';

  FALSE

  TRUE

 19. This statement should select all customers from the "Customers" table, sorted by the "Country" column. Fill in the blanks
SELECT * FROM Customers
_______ BY Country;

  WHERE

  ORDER

  SORT

  SORTED

 20. The following SQL statement selects all customers from the "Customers" table, sorted DESCENDING by the "Country" column. Fill in the blanks
SELECT * FROM Customers
ORDER BY Country _____

  DESC;

  SORT DOWN

  ORDER -

  "-1"