SQL interview questions

SQL quiz questions

  • 1.

    What is a view? Why should you use a view?

    Answer:

    A view is a logical snapshot based on a table or another view. It is used for −

    • Restricting access to data;
    • Making complex queries simple;
    • Ensuring data independency;
    • Providing different views of same data.
    View
  • 2.

    Which SQL statement is used to add, modify or drop columns in a database table?

    Answer:

    The ALTER TABLE statement.

    View
  • 3.

    Say True or False. Give explanation if False.

    A DROP TABLE statement can be rolled back.

    Answer:

    False. A DROP TABLE statement cannot be rolled back.

    View
  • 4.

    What is the difference between VARCHAR2 AND CHAR datatypes?

    Answer:

    VARCHAR2 represents variable length character data, whereas CHAR represents fixed length character data.

    View
  • 5.

    What is the purpose of the MERGE statement in SQL?

    Answer:

    The MERGE statement allows conditional update or insertion of data into a database table. It performs an UPDATE if the rows exists, or an INSERT if the row does not exist.

    View
  • 6.

    Can you remove rows from a table based on values from another table? Explain.

    Answer:

    Yes, subqueries can be used to remove rows from a table based on values from another table.

    View
  • 7.

    What happens if you omit the WHERE clause in a delete statement?

    Answer:

    All the rows in the table are deleted.

    View
  • 8.

    Say True or False. Give explanation if False.

    The DELETE statement is used to delete a table from the database.

    Answer:

    False. The DELETE statement is used for removing existing rows from a table.

    View
  • 9.

    Can you modify the rows in a table based on values from another table? Explain.

    Answer:

    Yes. Use of subqueries in UPDATE statements allow you to update rows in a table based on values from another table.

    View
  • 10.

    What happens if you omit the WHERE clause in the UPDATE statement?

    Answer:

    All the rows in the table are modified.

    View
  • 11.

    How do you copy rows from one table to another?

    Answer:

    The INSERT statement can be used to add rows to a table by copying from another table. In this case, a subquery is used in the place of the VALUES clause.

    View
  • 12.

    Say True or False. Give explanation if False.

    INSERT statement does not allow copying rows from one table to another.

    Answer:

    False. INSERT statement allows to add rows to a table copying rows from an existing table.

    View
  • 13.

    How do you insert null values in a column while inserting data?

    Answer:

    Null values can be inserted into a table by one of the following ways −

    • Implicitly by omitting the column from the column list.
    • Explicitly by specifying the NULL keyword in the VALUES clause.
    View
  • 14.

    Which statement is used to add a new row in a database table?

    Answer:

    The INSERT INTO statement.

    View
  • 15.

    What is the pupose of DML statements in SQL?

    Answer:

    The DML statements are used to add new rows to a table, update or modify data in existing rows, or remove existing rows from a table.

    View
  • 16.

    What are the various multiple row comparison operators in SQL?

    Answer:

    IN, ANY, ALL.

    View
  • 17.

    What’s wrong in the following query?

       SELECT student_code, name
       FROM students
       WHERE marks = 
                   (SELECT MAX(marks)
                      FROM students
                      GROUP BY subject_code);

    Answer:

    Here a single row operator = is used with a multiple row subquery.

    View
  • 18.

    Say True or False. Give explanation if False.

    A single row subquery returns only one row from the outer SELECT statement

    Answer:

    False. A single row subquery returns only one row from the inner SELECT statement.

    View
  • 19.

    What do you understand by a subquery? When is it used?

    Answer:

    A subquery is a SELECT statement embedded in a clause of another SELECT statement. It is used when the inner query, or the subquery returns a value that is used by the outer query. It is very useful in selecting some rows in a table with a condition that depends on some data which is contained in the same table.

    View
  • 20.

    Say True or False. Give explanation if False.

    Group functions cannot be nested.

    Answer:

    False. Group functions can be nested to a depth of two.

    View

© 2017 QuizBucket.org