Computer Knowledge

Database and SQL

3,929 Questions

Master structured query language commands, database joins, table constraints, and alias generation. This section covers relational database management concepts and query outputs essential for technical aptitude. These technical questions feature prominently in banking IT officer exams and computer knowledge sections.

SQL queries and aliasesDatabase table constraintsDatabase joins and transformationsStored procedures and functions

Database and SQL Questions

Multiple choice technology databases
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

A non-equi-join is defined as a join condition that uses comparison operators other than equality (=). These include operators like <, >, <=, >=, <>, BETWEEN, LIKE, etc. For example, finding employees whose salary is greater than the department average uses a non-equi-join. The statement is accurate, so 'True' is correct.

Multiple choice technology databases
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

You CAN sort SQL results by column alias - this is a standard SQL feature. The ORDER BY clause can reference column aliases defined in the SELECT list, even though the alias doesn't exist in the original table. This is because ORDER BY is logically processed after SELECT, so the aliases are available. The statement claims sorting by alias is not possible, which is false.

Multiple choice technology databases
  1. Single-row Functions and Double-row Functions

  2. One-row Functions and Two-row Functions

  3. Single-row Functions and Multiple-row Functions

  4. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

SQL functions are categorized into two main types: single-row functions (which operate on each row independently) and multiple-row functions (also called aggregate or group functions) which operate on groups of rows. Options A and B invent non-existent categories. This classification is fundamental to understanding SQL function behavior.

Multiple choice technology databases
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Single-row functions return exactly ONE result per input row, not multiple results. This is why they're called 'single-row' functions - they maintain a one-to-one relationship between input rows and output rows. They may transform the data (change data type, format, etc.), but they never produce multiple output rows from a single input row. Multiple-row functions (aggregates) can reduce many rows to one result, but single-row functions do not.

Multiple choice technology databases
  1. Return records which have no direct match

  2. Return records which have direct match

  3. Return all the records

  4. None of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

While an inner join only returns rows with matching values in both tables, an outer join also retrieves rows from one or both tables that do not have a corresponding match in the other, filling missing values with NULL. This makes it ideal for finding unmatched records.

Multiple choice technology databases
  1. (+)

  2. (-)

  3. (*)

  4. +

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In Oracle SQL, the (+) operator is used for outer joins in the WHERE clause syntax. For example, WHERE table1.column = table2.column(+) indicates a right outer join (rows from table2 are preserved). The (-) and * and + alone are not outer join operators.

Multiple choice technology databases
  1. Selfjoin

  2. Outerjoin

  3. innerjoin

  4. equijoin

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

A self-join joins a table to itself, typically to compare rows within the same table. It requires table aliases to distinguish the two instances of the table. Outer join returns all rows from one table plus matching rows from another. Inner join returns only matching rows. Equi-join is a join using = operator.

Multiple choice technology databases
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Group functions (aggregate functions like COUNT, SUM, AVG, MAX, MIN) cannot be used in WHERE clause. WHERE filters individual rows before grouping. Group functions must be used in HAVING clause or SELECT list, after grouping has occurred. This is a fundamental SQL rule.

Multiple choice technology databases
  1. All rows of the Employee table

  2. Rows of the Employee table where the set grade is ‘Y’

  3. Delete 1 row

  4. Nothing will be deleted

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The DELETE statement with a WHERE clause specifically removes only those rows that satisfy the condition. This statement will delete all employee records where the grade column equals 'Y', leaving other rows untouched.

Multiple choice technology databases
  1. CHECK keyword

  2. WITH CHECK keyword

  3. WITH CHECK OPTION keyword

  4. None of the Above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

WITH CHECK OPTION is a clause used with updatable views that prevents INSERT or UPDATE operations on rows that would not be visible through the view. It ensures that DML operations only affect rows that satisfy the subquery defining the view.

Multiple choice technology databases
  1. INSERT statement

  2. UPDATE statement

  3. Both of the Above

  4. None of the Above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The DEFAULT keyword can be explicitly used in both INSERT and UPDATE statements to assign a column's default value. In INSERT, you can specify VALUES (DEFAULT), and in UPDATE, you can use SET column = DEFAULT.

Multiple choice technology databases
  1. Count

  2. Avg

  3. Total

  4. Max

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Standard SQL aggregate functions include COUNT, AVG, MAX, MIN, and SUM. TOTAL is not a valid SQL aggregate function. To sum values, use the SUM function instead.

Multiple choice technology databases
  1. No. of rows in a table

  2. No. of rows with non-null values of the expr

  3. No. of distinct non-null values of the expr

  4. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

COUNT(DISTINCT expr) returns the number of unique, non-null values for the specified expression. It eliminates both NULL values and duplicate values from the count, giving the count of distinct values present.