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. 2

  2. 1

  3. 0

  4. error

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

In Oracle SQL, the LENGTH function returns NULL when given a negative number input. When you execute 'SELECT length(-1) FROM dual', Oracle implicitly converts -1 to a string, but LENGTH(-1) evaluates to NULL, not the count of digits. This is specific Oracle behavior for the LENGTH function with negative numeric inputs.

Multiple choice technology databases
  1. 14

  2. >14

  3. error

  4. <14

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

The COUNT(column) function ignores NULL values. Since one of the 14 records has a NULL value in the mgr column, COUNT(mgr) will return 13, which is less than 14.

Multiple choice technology databases
  1. Composite primarykey

  2. Not null

  3. unique

  4. check

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

In SQL, a composite primary key (primary key spanning multiple columns) must be declared using table-level constraint syntax. Column-level constraints apply to single columns only. NOT NULL (B), UNIQUE (C), and CHECK (D) can all be declared at column level. Only composite primary keys require the table CONSTRAINT syntax like CONSTRAINT pk_name PRIMARY KEY (col1, col2).

Multiple choice technology web technology
  1. The Constraint condition is never checked

  2. The Constraint condition is checked only at the time of commiting the transaction

  3. The Constraint condition is checked only for newly inserted rows and will not be checked for already existing rows in the table

  4. The constraint condition is checked after a predefined time interval

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

Deferred constraints in Oracle are checked only when the transaction is committed, not immediately after each DML statement. This allows temporary violations during a transaction as long as constraints are satisfied by commit time. Option A is false - constraints ARE checked. Option C describes a validated constraint, not deferred. Option D is false - there is no time interval-based checking.

Multiple choice technology databases
  1. varchar is used to store fixed length character data, varchar2 is for variable length character data

  2. varchar data type is not supported in oracle

  3. varchar data type is applicable only to PL/SQL

  4. maximum length for varchar is 2000 bytes and for varchar2 is 4000 bytes

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

In Oracle, VARCHAR max length is 2000 bytes while VARCHAR2 max is 4000 bytes. VARCHAR is included only for backward compatibility and should not be used for new code. Both types work in SQL and PL/SQL, and both store variable-length character data.

Multiple choice technology databases
  1. The Constraint condition is never checked

  2. The Constraint condition is checked only at the time of commiting the transaction

  3. The Constraint condition is checked only for newly inserted rows and will not be checked for already existing rows in the table

  4. The constraint condition is checked after a predefined time interval

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

Deferred constraints in Oracle defer checking until the transaction is committed. This allows temporary violations during intermediate transaction steps, which are resolved before the changes are permanently saved.

Multiple choice technology databases
  1. drop foreign keys

  2. cascade constraints

  3. this is not possible in oracle

  4. clear references

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

The CASCADE CONSTRAINTS clause in a DROP TABLE statement automatically drops any referential integrity constraints (foreign keys in child tables) that refer to primary or unique keys in the table being dropped.

Multiple choice technology databases
  1. specifies that the empty space created by deleting the records must be retained for this table and should not be used by other tables

  2. specifies that the empty space created by deleting the records, can be used by other tables.

  3. specifies that this transaction can be rolled back later

  4. This clause cannot be used with truncate statement

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

The REUSE STORAGE clause in TRUNCATE specifies that the space freed by deleting rows remains allocated to the table (kept in its tablespace). The default DROP STORAGE would return that space to the tablespace for other tables to use. TRUNCATE cannot be rolled back.