Essential SQL - Quiz Answers

The answers you selected are indicated below, along with text that explains the correct answers.
 
1. Which of the following statements is correct?
Please select the best answer.
  A. SELECT CustNo, LName, FName ORDER BY Zip
  B. SELECT * FROM CustTable ORDER BY State
  C. SELECT * FROM CustTable ORDER BY St = 'AZ'
  D. SELECT * FROM CustTable ORDER BY CustNo
  D is the correct answer. D is the correct answer because it uses correct syntax, and specifies the correct table and column. Answer A is incorrect because a table is not specified. Answer B is incorrect because State is not a valid column name. Answer C is incorrect because the ORDER BY clause uses only a column name, not a value.

2. Which of the following statements will delete inactive customer records?
Please select the best answer.
  A. DELETE * FROM CustTable WHERE Status = 'I'
  B. DELETE FROM CustTable WHERE Status = 'I'
  C. DELETE FROM CustTable
  D. DELETE * WHERE Status = 'I'
  B is the correct answer. B is the correct answer because it's complete and syntactically correct.
Answer A is incorrect because column names and the (*) aren't specified in the DELETE statement. Answer C is incorrect because it deletes all records. Answer D is incorrect because it doesn't specify a table and the * is not used in the DELETE statement.


3. Which of the following statements correctly changes customers in Ohio to inactive status?
Please select the best answer.
  A. UPDATE CustTable SET Status = 'I' WHERE ST = 'OH'
  B. UPDATE CustTable (Status) WHERE ST='OH' VALUES ('I')
  C. UPDATE Status FROM CustTable WHERE ST = 'I'
  D. UPDATE Status WHERE ST='OH' SET Status = 'I'
  A is the correct answer. A is the correct answer because it is complete and syntactically correct and complete. Answers B is incorrect because the Status column is incorrectly specified and the use of VALUES is incorrect. Answer C specifies inactive for the state and the syntax is incorrect. Answer D is incorrect because the table is not specified and the syntax is incorrect.

4. Which of the following statements adds a record to CustTable and correctly assigns values to the CustNo, LName, and FName columns?
Please select the best answer.
  A. INSERT (CustNo,LName,FName) INTO CustTable VALUES ('00005','Jones','Tom')
  B. INSERT INTO CustTable (CustNo,LName,FName) VALUES ('00005','Jones','Tom')
  C. INSERT INTO CustTable (CustNo, LName,FName) VALUES ('Jones','Tom')
  D. INSERT VALUES ('00005','Jones','Tom') INTO CustTable (CustNo, LName,FName)
  B is the correct answer because it is complete and syntactically correct.
Answer A is incorrect because the column list should follow the table name. Answer C is incorrect because the customer number value is not specified in the VALUES list. Answer D is incorrect because the table, column names, and value specifiers are not in the correct order and the INSERT INTO statement is incorrectly used.