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

SQL allows sorting by multiple columns using comma-separated column names in the ORDER BY clause: 'ORDER BY col1, col2, col3'. The practical limit is indeed the number of columns in the table or result set, though very large numbers of sort columns are rare in practice. Multi-column sorting creates a hierarchical sort where results are ordered by the first column, then ties within that column are ordered by the second column, and so on.

Multiple choice technology databases
  1. A SCHEMA with CREATE SESSION system privilege

  2. CREATE SYNONYM system privilege

  3. A storage area with required access

  4. CREATE TABLE system privilege

  5. CREATE INDEX system privilege

Reveal answer Fill a bubble to check yourself
A,C,D Correct answer
Explanation

To create a table, you need CREATE TABLE privilege, CREATE SESSION to connect, and storage area access (tablespace quota). CREATE SYNONYM and CREATE INDEX are separate privileges - a synonym is an alias and indexes are optional database objects that can be created separately.

Multiple choice technology databases
  1. UPDATE the records in the table

  2. MODIFY the data type of the column

  3. DROP the table column

  4. DEFINE a default value for the column

  5. DELETE the records in the table

  6. ADD a new column to the table

Reveal answer Fill a bubble to check yourself
B,C,D,F Correct answer
Explanation

The ALTER TABLE statement in SQL allows modifications to a table's structure, including modifying column data types (MODIFY), removing columns (DROP), setting defaults (ALTER/MODIFY), and adding columns (ADD). It does not manipulate table records; UPDATE and DELETE are distinct DML operations.

Multiple choice technology databases
  1. TRUNCATE is DDL and DELETE is DML

  2. TRUNCATE is DML and DELETE is DDL

  3. TRUNCATE is DCL and DELETE is DML

  4. TRUNCATE is DML and DELETE is DCL

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

TRUNCATE is a Data Definition Language (DDL) command that quickly deletes all rows by deallocating the table's storage, which cannot be rolled back. DELETE is a Data Manipulation Language (DML) command that removes rows one by one, generating undo logs that allow rollbacks.

Multiple choice technology databases
  1. Can be defined on a single column or multiple columns in the table.

  2. Can be defined only on a single column in the table.

  3. A UNIQUE index is automatically created once PRIMARY KEY is defined on the table.

  4. A NON-UNIQUE index is automatically created once PRIMARY KEY is defined on the table.

  5. NOT NULL constraint is implicitly enforced on the columns which are part of the PRIMARY KEY

  6. NULL constraint is implicitly enforced on the columns which are part of the PRIMARY KEY

Reveal answer Fill a bubble to check yourself
A,C,E Correct answer
Explanation

A PRIMARY KEY can be defined on single or multiple columns (composite key), automatically creates a UNIQUE index to enforce uniqueness, and implicitly adds NOT NULL constraint because NULL values would violate uniqueness. Options claiming single-column only, NON-UNIQUE index, or NULL constraints are incorrect.

Multiple choice technology databases
  1. Can be defined only on a single column in the table.

  2. Can be defined on a single column or multiple columns in the table.

  3. A UNIQUE index is automatically created once UNIQUE KEY is defined on the table.

  4. A NON-UNIQUE index is automatically created once UNIQUE KEY is defined on the table.

  5. NULL values are NOT acceptable on the columns, which are part of UNIQUE KEY

  6. NULL values are acceptable, which are part of UNIQUE KEY

Reveal answer Fill a bubble to check yourself
B,C,F Correct answer
Explanation

A UNIQUE constraint can be defined on single or multiple columns and automatically creates a unique index to enforce uniqueness. Unlike primary keys, columns with a unique key constraint are permitted to contain NULL values, making the selected options correct.

Multiple choice technology databases
  1. Must be defined as a part of column definition

  2. It's NOT necessary to define it as a part of column definition

  3. Can be applied to the column which may hold UNKNOWN data

  4. Can NOT be applied to the column which may hold UNKNOWN data

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

NOT NULL must be defined as part of the column specification (inline or table-level but with column context). Since NOT NULL prohibits NULL values, it cannot be applied to columns that legitimately hold unknown/missing data - that's the purpose of allowing NULLs.

Multiple choice technology databases
  1. Must evaluate to BOOLEAN expression

  2. Not necessarily evaluates to BOOLEAN expression

  3. Requires that a column (or combination of columns) satisfy a condition for every row in the table excluding nulls.

  4. Columns which, are part of CHECK constraint, may accept NULL values

  5. Columns which, are part of CHECK constraint, can NOT accept NULL values

Reveal answer Fill a bubble to check yourself
A,C,D Correct answer
Explanation

CHECK constraints must evaluate to a BOOLEAN expression (true/false), apply to every row excluding nulls (nulls don't trigger CHECK constraint violations), and columns in CHECK constraints can accept NULLs unless explicitly restricted by NOT NULL. The constraint only fails when a non-null value violates the condition.

Multiple choice technology databases
  1. Defines relations between the tables

  2. The table that includes the foreign key is called the dependent or child table

  3. The table that includes the foreign key is called the parent table

  4. The table that is referenced by the foreign key is called the parent table

  5. The table that is referenced by the foreign key is called the dependent or child table

Reveal answer Fill a bubble to check yourself
A,B,D Correct answer
Explanation

A foreign key establishes a relationship between two tables, ensuring referential integrity. The table containing the foreign key is the dependent or child table, while the referenced table containing the primary or unique key is the parent table, confirming the selected options.

Multiple choice technology databases
  1. True

  2. False

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

Using the ALTER TABLE statement, constraints can be added, dropped, enabled, or disabled, but their internal structure (such as the columns they reference) cannot be directly modified. To modify a constraint's definition, you must drop it and recreate it, validating the statement as true.

Multiple choice technology databases
  1. It is a DML command

  2. It is a DDL command

  3. Provides the ability to conditionally update or insert data into a database table

  4. Provides the ability to MERGE VIEWS and INDICES of a TABLE

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

MERGE is a DML (Data Manipulation Language) command, not DDL, because it modifies existing data in tables. It provides UPSERT functionality - conditionally updating existing rows or inserting new ones based on a matching condition. Option D is incorrect because MERGE operates on table data, not on schema objects like views or indices.

Multiple choice technology databases
  1. EQUI-JOIN

  2. NONEQUI-JOIN

  3. SELF-JOIN

  4. OUTER-JOIN

  5. MERGE-JOIN

  6. TRANSACTION-JOIN

Reveal answer Fill a bubble to check yourself
A,B,C,D Correct answer
Explanation

Standard SQL JOIN types include EQUI-JOIN (joins on equality condition), NON-EQUI-JOIN (joins on non-equality conditions like >, <, BETWEEN), SELF-JOIN (joining a table to itself), and OUTER-JOIN (includes unmatched rows with NULLs). MERGE-JOIN is a join algorithm/implementation method, not a JOIN type. TRANSACTION-JOIN is not a standard SQL concept.

Multiple choice technology databases
  1. SELECT

  2. WHERE

  3. GROUP BY

  4. FROM

  5. ORDER BY

  6. HAVING

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

The SELECT statement requires only SELECT and FROM clauses to be valid - these specify what to retrieve and where from. WHERE, GROUP BY, ORDER BY, and HAVING are optional clauses that filter rows, group results, sort output, and filter groups respectively. A query like 'SELECT column FROM table;' is perfectly valid.