SQL Views Quiz - Explanation

The correct answers are indicated below, along with text that explains the correct answers.
 
1. Which of the following can be characteristic(s) of a view?
  A. A view can include WHERE statements
  B. A view can be permanently saved in the database with the table
  C. A view can include joins between more than one table
  D. All of the above
  The correct answer is D.
All the choices represent characteristics of views.

2. Which of the following is/are not good uses for a view?
  A. You need to combine two tables logically and be able to update the information repeatedly based on criteria in a SELECT statement
  B. You need to select different columns from a table every time you run a given query
  C. You need to select from different tables with a similar query
  D. All of the above are good uses for a view
  The correct answer is C.
If you are selecting from different tables, you won't be able to use a view. Because the underlying tables are called out in the SELECT statement that defines the view, you can't change them on the fly. You should just use a standard SELECT statement in that case.

3. Which of the following is a specific benefit of a view?
  A. Speed, because the query results are returned more quickly
  B. Convenience, by having a predefined SELECT statement
  C. Access, because making a view grants the user permission to use the tables
  D. Security, because views can be used to prevent people from updating the database accidentally
  The correct answer is B.
Choice A, speed, is really not a benefit of a view since the database still has to do all the work. Choice C is incorrect because the user does not gain access to the underlying table simply by creating a view. Choice D is incorrect because views do not, in and of themselves, prevent the user from updating the database. The inability comes from other factors, such as the lack of unique keys, security, and so on.

4. Given the following tables:
Stores
StoreName StoreLocation
Invoices
InvoiceID InvoiceAmount
Is the following view updateable?
 
CREATE VIEW MyView AS 
SELECT * FROM Stores, Invoices
  A. Yes, because the tables are in the same database
  B. Yes, because the CREATE VIEW statement references both tables
  C. No, because there is no unique key defined for the tables
  D. No, because you cannot use a * symbol in this statement
  The correct answer is C.
In order to update the tables using a view, you must have unique identifiers for each row.