Basic SQL Quiz - 2

Basic SQL Quiz - 2

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

With SQL, how do you select all the records from a table named "Persons" where the "FirstName" is "Peter" and the "LastName" is "Jackson"?

  1. SELECT * FROM Persons WHERE FirstName LIKE 'Peter' AND LastName LIKE 'Jackson'
  2. SELECT * FROM Persons WHERE FirstName='Peter' AND LastName='Jackson'
  3. SELECT FirstName='Peter', LastName='Jackson' FROM Persons
Question 2 Multiple Choice (Single Answer)

With SQL, how do you select all the records from a table named "Persons" where the "LastName" is alphabetically between (and including) "Hansen" and "Pettersen"?

  1. SELECT LastName>'Hansen' AND LastName<'Pettersen' FROM Persons
  2. SELECT * FROM Persons WHERE LastName BETWEEN 'Hansen' AND 'Pettersen'
  3. SELECT * FROM Persons WHERE LastName>'Hansen' AND LastName<'Pettersen'
Question 3 Multiple Choice (Single Answer)

Which SQL statement is used to return only different values?

  1. SELECT UNIQUE
  2. SELECT INDENTITY
  3. SELECT DIFFERENT
  4. SELECT DISTINCT
Question 4 Multiple Choice (Single Answer)

Which SQL keyword is used to sort the result-set?

  1. SORT BY
  2. ORDER
  3. ORDER BY
  4. SORT
Question 5 Multiple Choice (Single Answer)

With SQL, how can you return all the records from a table named "Persons" sorted descending by "FirstName"?

  1. SELECT * FROM Persons SORT BY 'FirstName' DESC
  2. SELECT * FROM Persons ORDER BY FirstName DESC
  3. SELECT * FROM Persons ORDER FirstName DESC
  4. SELECT * FROM Persons SORT 'FirstName' DESC
Question 6 Multiple Choice (Single Answer)

With SQL, how can you insert a new record into the "Persons" table?

  1. INSERT INTO Persons VALUES ('Jimmy', 'Jackson')
  2. INSERT ('Jimmy', 'Jackson') INTO Persons
  3. INSERT VALUES ('Jimmy', 'Jackson') INTO Persons
Question 7 Multiple Choice (Single Answer)

With SQL, how can you insert "Olsen" as the "LastName" in the "Persons" table?

  1. INSERT INTO Persons (LastName) VALUES ('Olsen')
  2. INSERT ('Olsen') INTO Persons (LastName)
  3. INSERT INTO Persons ('Olsen') INTO LastName
Question 8 Multiple Choice (Single Answer)

How can you change "Hansen" into "Nilsen" in the "LastName" column in the Persons table?

  1. UPDATE Persons SET LastName='Hansen' INTO LastName='Nilsen'
  2. UPDATE Persons SET LastName='Nilsen' WHERE LastName='Hansen'
  3. MODIFY Persons SET LastName='Hansen' INTO LastName='Nilsen
  4. MODIFY Persons SET LastName='Nilsen' WHERE LastName='Hansen'
Question 9 Multiple Choice (Single Answer)

With SQL, how can you delete the records where the "FirstName" is "Peter" in the Persons Table?

  1. DELETE FROM Persons WHERE FirstName = 'Peter'
  2. DELETE ROW FirstName='Peter' FROM Persons
  3. DELETE FirstName='Peter' FROM Persons
Question 10 Multiple Choice (Single Answer)

With SQL, how can you return the number of records in the "Persons" table?

  1. SELECT COLUMNS() FROM Persons
  2. SELECT COUNT(*) FROM Persons
  3. SELECT COLUMNS(*) FROM Persons
  4. SELECT COUNT() FROM Persons
Question 11 Multiple Choice (Single Answer)

What will be the output of the following statement? SELECT LEN(CAST(LEFT('026-100', 3) AS INT))

  1. 2
  2. 3
  3. 7
  4. Statement will generate an error.
Question 12 Multiple Choice (Single Answer)

What will be the output of the following statement? SELECT CAST(-1 AS SMALLDATETIME)

  1. 1900-01-01 00:00:00.000
  2. 1899-01-01 00:00:00.000
  3. 1752-01-01 00:00:00.000
  4. The system will generate an error. Only positive integer values can be converted to a SMALLDATETIME data type.
Question 13 Multiple Choice (Single Answer)

What will be the output of the following statement? SELECT ROUND(123.89, -1)

  1. 120.00
  2. 123.00
  3. 123.90
  4. 124.00
Question 14 Multiple Choice (Single Answer)

What will be the output of the following statement? SELECT STR(6365, 3)

  1. ***
  2. 6365
  3. 6,365
  4. 6400
  5. 6365.000
Question 15 Multiple Choice (Single Answer)

What will be the output of the following statement? SET ARITHABORT OFF SET ANSI_WARNINGS OFF SELECT 100/0

  1. Null
  2. 0
  3. Infinity
  4. An error is generated.
Question 16 Multiple Choice (Single Answer)

View text definitions are stored in which system table?

  1. sysobjects
  2. syscolumns
  3. syscomments
  4. sysviews
Question 17 Multiple Choice (Single Answer)

What's the maximum value can an INT data type hold?

  1. 2,147,483,647
  2. 2,147,483,648
  3. 4,294,967,295
  4. 4,294,967,296
Question 18 Multiple Choice (Single Answer)

What is the best data type to store the birthdays of the US Presidents, starting with George Washington's birthday of February 22, 1732?

  1. DATETIME
  2. INT
  3. SMALLDATETIME
  4. VARCHAR
Question 19 Multiple Choice (Single Answer)

Which of the following is NOT a valid description of the public role?

  1. The public role captures all default permissions for users in a database.
  2. The public role cannot be dropped.
  3. The public role is contained in every database, including msdb, tempdb, model, and all user databases except in the master database for security purposes.
  4. The public role cannot have users, groups, or roles assigned to it.
Question 20 Multiple Choice (Single Answer)

What is the maximum date value that can be stored in a SMALLDATETIME data type?

  1. June 6, 2079
  2. July 6, 2079
  3. December 31, 2079
  4. December 31, 9999