SQL quiz questions

SQL interview questions

  • 1.

    Select the code that would show the countries with an area larger than 50000 and a population smaller than 10000000

    1. SELECT name, area, population
        FROM world
       WHERE area < 50000 AND population < 10000000

       

    2. SELECT name, area, population
        FROM world
       WHERE area < 50000 AND population > 10000000

       

    3. SELECT name, area, population
        FROM world
       WHERE area > 50000 AND population < 10000000

       

    4. SELECT name, area, population
        FROM world
       WHERE area > 50000 AND population > 10000000

       

    5. SELECT name, area, population
        FROM world
       WHERE area = 50000 AND population = 10000000

       

    Answer
  • 2.

    Here are the first few rows of the world table:

    name region area population gdp
    Afghanistan South Asia 652225 26000000  
    Albania Europe 28728 3200000 6656000000
    Algeria Middle East 2400000 32900000 75012000000
    Andorra Europe 468 64000  
    ...

    Pick the result you would obtain from this code:

    SELECT name, area*2 FROM world WHERE population = 64000

     

    1. Andorra 234
    2. Andorra 468
    3. Andorra 936
    4. Andorra 4680
    5. Andorra 936
      Albania 57456
    Answer
  • 3.

    Pick the result from the query

    SELECT name,LENGTH(name)
    FROM world
    WHERE LENGTH(name)=5 AND region='Europe'

     

    1. name length(name)
      Benin 5
      Lybia 5
      Egypt 5
    2. name length(name)
      Italy 5
      Egypt 5
      Spain 5
    3. name length(name)
      Italy 5
      Malta 5
      Spain 5
    4. name length(name)
      Italy 5
      France 6
      Spain 5
    5. name length(name)
      Sweden 6
      Norway 6
      Poland 6
    Answer
  • 4.

    Pick the result you would obtain from this code:

          SELECT name, population
          FROM world
          WHERE name LIKE "Al%"

     

    1. Albania
      Algeria
    2. %bania 3200000
      %geria 32900000
    3. Al 0
    4. Albania 3200000
    5. Albania 3200000
      Algeria 32900000
    Answer
  • 5.

    Select the code which shows the countries that end in A or L

    1. SELECT name FROM world
       WHERE name LIKE 'a%' AND name LIKE 'l%'

       

    2. SELECT name FROM world
       WHERE name LIKE 'a%' OR name LIKE 'l%'

       

    3. SELECT name FROM world
       WHERE name LIKE '%a' AND name LIKE '%l'

       

    4. SELECT name FROM world
       WHERE name LIKE '%a' OR 'l%'

       

    5. SELECT name FROM world
       WHERE name LIKE '%a' OR name LIKE '%l'

       

    Answer
  • 6.

     

    Select the code which produces this table

    name population
    Bahrain 1234571
    Swaziland 1220000
    Timor-Leste 1066409
    1. FROM world
      SELECT name, population BETWEEN 1000000 AND 1250000

       

    2. FROM name, population 
      WHERE population BETWEEN 1000000 AND 1250000
      SELECT world

       

    3. SELECT name, population
        FROM world
       WHERE population BETWEEN 1000000 AND 1250000

       

    4. SELECT population BETWEEN 1000000 AND 1250000
      FROM world

       

    5. WHERE population BETWEEN 1000000 AND 1250000
      SELECT name, population FROM world

       

    Answer
  • 7.

    Which SQL statement is used to create a table in a database?

    1. CREATE DATABASE TABLE

    2. CREATE DB

    3. CREATE DATABASE TAB

    4. CREATE TABLE

    Answer
  • 8.

    Which operator is used to search for a specified pattern in a column?

    1. GET

    2. LIKE

    3. FROM

    Answer
  • 9.

    Which operator is used to search for a specified pattern in a column?

    1. GET

    2. LIKE

    3. FROM

    Answer
  • 10.

    The NOT NULL constraint enforces a column to not accept null values.

    1. True

    2. False

    Answer
  • 11.

    Which operator is used to select values within a range?

    1. RANGE

    2. WITHIN

    3. BETWEEN

    Answer
  • 12.

    What is the most common type of join?

    1. JOINED

    2. JOINED TABLE

    3. INSIDE JOIN

    4. INNER JOIN

    Answer
  • 13.

    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 COUNT() FROM Persons

    4. SELECT COLUMNS() FROM Persons

    Answer
  • 14.

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

    1. DELETE ROW FirstName='Peter' FROM Persons

    2. DELETE FirstName='Peter' FROM Persons

    3. DELETE FROM Persons WHERE FirstName = 'Peter'

    Answer
  • 15.

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

    1. DELETE ROW FirstName='Peter' FROM Persons

    2. DELETE FirstName='Peter' FROM Persons

    3. DELETE FROM Persons WHERE FirstName = 'Peter'

    Answer
  • 16.

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

    1. MODIFY Persons SET LastName='Hansen' INTO LastName='Nilsen

    2. UPDATE Persons SET LastName='Hansen' INTO LastName='Nilsen'

    3. UPDATE Persons SET LastName='Nilsen' WHERE LastName='Hansen'

    4. MODIFY Persons SET LastName='Nilsen' WHERE LastName='Hansen'

    Answer
  • 17.

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

    1. INSERT INTO Persons ('Olsen') INTO LastName

    2. INSERT ('Olsen') INTO Persons (LastName)

    3. INSERT INTO Persons (LastName) VALUES ('Olsen')

    Answer
  • 18.

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

    1. INSERT INTO Persons VALUES ('Jimmy', 'Jackson')

    2. INSERT VALUES ('Jimmy', 'Jackson') INTO Persons

    3. INSERT ('Jimmy', 'Jackson') INTO Persons

    Answer
  • 19.

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

    1. INSERT INTO Persons VALUES ('Jimmy', 'Jackson')

    2. INSERT VALUES ('Jimmy', 'Jackson') INTO Persons

    3. INSERT ('Jimmy', 'Jackson') INTO Persons

    Answer
  • 20.

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

    1. SELECT * FROM Persons SORT 'FirstName' DESC

    2. SELECT * FROM Persons SORT BY 'FirstName' DESC

    3. SELECT * FROM Persons ORDER FirstName DESC

    4. SELECT * FROM Persons ORDER BY FirstName DESC

    Answer

© 2017 QuizBucket.org