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 mainframe
  1. Name, DD, Space, Device

  2. Format, Name, DD, Space

  3. DD, parameter, device, format

  4. Name, DD, parameter, comments

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

A JCL DD statement consists of four fields in order: Name (the ddname), DD (the statement type), parameter (various parameters like DSN, DISP, SPACE), and comments (optional). Options A, B, and C either misorder the fields or include non-standard field names. 'Device' and 'format' are not among the four main fields.

Multiple choice technology databases
  1. foreign key constraint

  2. unique key constraint

  3. check constraint

  4. All of the above

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

Foreign key, unique key, and check constraints all permit NULL values by default unless they are explicitly paired with a NOT NULL constraint.

Multiple choice technology databases
  1. deletes data from table_name which cannot be rolled back

  2. deletes data from table_name but can be rolled back

  3. drops table_name

  4. none of the above

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

DELETE is a DML (Data Manipulation Language) command that can be rolled back using ROLLBACK if not committed. It removes data but preserves table structure. DROP TABLE removes the entire table (DDL, not rollable).

Multiple choice technology databases
  1. both column data type must be same

  2. both colmun data type need not be same

  3. one of the data type must be different

  4. both column data type and length must be same

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

A composite key combines multiple columns as a primary key. The columns can have different data types - there's no requirement for type matching. Only the combination of values must be unique.

Multiple choice technology databases
  1. check (salary>(select salary from emp where uid=10))

  2. check (salary >(select salary from emp where rowid=10 ))

  3. check (salary >2568)

  4. check (salary >select salary from emp where dno=10)

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

CHECK constraints cannot contain subqueries or references to other rows - they must evaluate to a boolean condition using only the current row's values. Option C uses a literal value (2568), making it valid. Options A, B, and D use subqueries, which are not allowed.

Multiple choice technology databases
  1. deletes data from table but keeps table structure

  2. deletes data as well table structure

  3. drops table

  4. none of the above

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

TRUNCATE removes all rows from a table but preserves the table structure and associated objects (indexes, constraints). Unlike DELETE, TRUNCATE is DDL (cannot be rolled back) and is faster for removing all data.

Multiple choice technology databases
  1. 1 11 111 2 3 4

  2. 1 2 3 4 11 111

  3. 111 11 4 3 2 1

  4. ERROR due to data type mismatch

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

VARCHAR columns store character data, so ORDER BY uses lexicographic (dictionary) sorting, not numeric. String '11' comes before '2' because '1' < '2'. The sorted order is: 1, 11, 111, 2, 3, 4.

Multiple choice technology databases
  1. Union all will remove the duplicate rows from the result set while Union does'nt

  2. Union will remove the duplicate rows from the result set while Union all does'nt

  3. Both Union and Union all will remove duplicate rows from result set

  4. All of the above

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

The UNION operator combines the results of two queries and removes duplicate rows, whereas UNION ALL combines the results and includes all duplicates, making UNION slower but cleaner.

Multiple choice technology databases
  1. Unique

  2. Non Unique

  3. Null

  4. Not Null

  5. All of the above

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

A Primary Key constraint enforces two database integrity rules: every value in the primary key column(s) must be unique, and no value in the primary key column(s) can be null.

Multiple choice technology databases
  1. 5392845.324

  2. 871039453.1

  3. 97234512.123

  4. 1234567.12

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

A column defined as NUMBER(10,2) can hold up to 10 significant digits, with 2 of those to the right of the decimal point (leaving 8 digits for the integer part). '871039453.1' has 9 integer digits, causing an overflow error.

Multiple choice technology databases
  1. 0

  2. 1

  3. 2

  4. error

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

The LENGTH function in Oracle/SQL counts the number of characters in a string expression, including special characters and signs. For LENGTH(-1), the function treats '-1' as a two-character string (minus sign and digit 1), not as a numeric value. The output is 2, not 1 (the digit count) or 0. This demonstrates that LENGTH operates on string representation, not mathematical values.

Multiple choice technology databases
  1. <14

  2. >14

  3. 14

  4. 0

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

COUNT(column_name) explicitly ignores NULL values in the specified column. With 14 total rows and one NULL in MGR, COUNT(mgr) returns 13 (not 14). This differs from COUNT(*) which counts all rows regardless of NULL values. Option A correctly states the result is less than 14, though the precise value is 13. The question tests understanding of aggregate function behavior with NULL values.