Computer Knowledge

Database and SQL

4,213 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. Alter

  2. Grant

  3. Select

  4. Rename

  5. Revoke

  6. Update

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

Data Control Language (DCL) commands manage permissions and access: Grant gives privileges to users, Revoke removes privileges. Alter and Rename are DDL structure commands, Select retrieves data, Update modifies data - none are access control commands.

Multiple choice technology databases
  1. True

  2. False

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

A table in RDBMS follows the relational model's two-dimensional structure: rows (also called tuples or records) represent individual entries, and columns (attributes or fields) represent properties. This grid-like structure is fundamental to how relational databases organize and store data.

Multiple choice technology databases
  1. True

  2. False

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

In SQL SELECT statement syntax, ORDER BY is indeed the final clause. The standard order is: SELECT → FROM → WHERE → GROUP BY → HAVING → ORDER BY. This makes sense logically because you must first determine which rows and columns you're working with before sorting them.

Multiple choice technology databases
  1. True

  2. False

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

The default sort order for ORDER BY in SQL is ascending (ASC), not descending. If you omit ASC/DESC, the database assumes you want ascending order. To sort in descending order, you must explicitly specify the DESC keyword.

Multiple choice technology databases
  1. True

  2. False

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

In SQL, the SELECT clause is processed before the ORDER BY clause in the logical query processing phase. Consequently, column aliases defined in the SELECT clause are visible and can be used to sort the result set in the ORDER BY clause.

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.