Homechevron_rightEngineeringchevron_rightRPSC Programmerchevron_rightProgrammer DBMSchevron_rightSQL

SQL MCQs

  • 1. In SQL, the _______ command is used to recompile view.
  • filter_dramaExplanation
    Answer is : C

    Concept:

    A VIEW is a logical representation of another table or combination of tables. A view derives its data from the tables on which it is based. These tables are called base tables

    Explanation:

    • ALTER VIEW statement is used to explicitly recompile a view that is invalid or to modify view constraints.
    •  Explicit recompilation lets operator locate recompilation errors before run time.
    • One may want to recompile a view explicitly after altering one of its base tables to ensure that the alteration does not affect the view or other objects that depend on it.
    • ALTER VIEW is a used to define, modify, or drop view constraints.
  • 2.

    Which of the following statements are true?

    i) DDL Compiler is a Query processor component

    ii) DML Compiler is a Query Processor component

    iii) Query evaluation engine is a Query Processor component

  • filter_dramaExplanation
    Answer is : D

    Query Processor:

    • The query processor is used to interpret the online user query and converts it into an efficient series of operation in a form capable of being sent to the data manager for execution.
    • The query processor uses the data dictionary to find the structure of the relevant portion of the database and use this information in modifying the query and prepare an optimal plan to access the database.
    • It is a program module that provides the interface between the database and the application programs/queries.

     

    The Query Processor Components include:

    Data Definition Language(DDL) Compiler: DDL compiler takes the data definition statement that is the source form & convert them into the object form (or) interprets DDL commands and records them in the data dictionary.

    Data Modelling Language (DML) compilertranslates DML commands into query evaluation plans.

    Query evaluation engine: executes queries according to the plans

  • 3. Which of the following command is used to add attributes to an existing relation?
  • filter_dramaExplanation
    Answer is : D

    The alter table command to add attributes to an existing relation. All tuples in the relation are assigned null as the value for the new attribute. The form of the alter table command is

    alter table r add A D;

    where r is the name of an existing relation, A is the name of the attribute to be added, and D is the type of the added attribute.
  • 4. SELECT operation in SQL is equivalent to
  • filter_dramaExplanation
    Answer is : D
    Select operation is equivalent to the projection operation in relational algebra, except that select in SQL retains duplicates and on the contrary projection removes the duplicates.
  • 5. ________ is used to test empty relations.
  • filter_dramaExplanation
    Answer is : D

    SQL includes a feature for testing whether a subquery has any tuples in its result.

    The ‘exists’ construct returns the value true if the argument subquery is nonempty.
  • 6. Which of the following PL/SQL component stores data?
  • filter_dramaExplanation
    Answer is : C

    PL/SQL block has the actual PL/SQL code.

    PL/SQL engine is the component where the actual processing of the codes takes place.

    Database server is the most important component of Pl/SQL unit which stores the data.
  • 7. In SQL, TRUNCATE command is a ________ statement.
  • filter_dramaExplanation
    Answer is : C
    In SQL, TRUNCATE TABLE command is used to delete complete data from an existing table. So it is a DDL (Data Definition Language) statement.
  • 8. What are the different sections of PL/SQL block?
  • filter_dramaExplanation
    Answer is : C

    PL/SQL blocks have a pre-defined structure in which the code is to be grouped. Below are different sections of PL/SQL blocks.

    • Declaration section
    • Execution section
    • Exception-Handling section
    Out of which only execution section is mandatory.
  • 9.

    Which of the query in SQL is an example of self-join?

    I. SELECT a.column_name FROM table1 a, table1 b WHERE a.x = b.x;

    II. SELECT b.column_name FROM table1 a, table2 b WHERE a.y = b.y;
  • filter_dramaExplanation
    Answer is : A
    • A self-join is a join in which a table is joined with itself (which is also called Unary relationships), especially when the table has a FOREIGN KEY which references its own PRIMARY KEY
    • To join a table itself means that each row of the table is combined with itself and with every other row of the table
    • In query 1, only one relation is used, that is, table1 and hence it is a self-join but in query II, two different relations are used, that is, table1 and table2 and hence it cannot be an example of self-join
  • 10. Which is not aggregate function in SQL?
  • filter_dramaExplanation
    Answer is : B

    Aggregate functions return a single result row based on groups of rows, rather than on single rows. Aggregate functions can appear in select lists and in ORDER BY and HAVING clauses.

    Function

    Description

    COUNT

    COUNT returns the number of rows returned by the query

    AVG

    AVG returns average value of expression

    MIN

    MIN returns minimum value of expression

    SUM

    SUM returns the sum of values of expression

     

    Note:

    AVG is aggregate function but not AVERAGE
leaderboardLeaderboard
  • Rahul Kumar

    191 Points

  • VIKRAM JEET

    54 Points

  • GEETHIKA CHOWDARY

    53 Points

  • sunita saini

    52 Points

  • Zain

    49 Points