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

  2. 871039453.1

  3. 97234512.123

  4. 1234567.12

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

NUMBER(10,2) means total 10 digits with 2 after decimal, so max 8 digits before decimal (10-2=8). Option B has 9 digits before the decimal (871039453), which exceeds the allowed precision and causes an error. Option C has 3 decimal places but only 8 integer digits, so it would round to 97234512.12 without error. Oracle rounds values that exceed scale but fits within precision, only errors when integer part exceeds allowed digits.

Multiple choice technology databases
  1. where

  2. having

  3. order by

  4. none of the above

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

Subqueries in SQL cannot use ORDER BY clause because subqueries return a set of rows used by the outer query, and the outer query determines the final ordering. However, subqueries can use WHERE for row filtering and HAVING for group filtering. ORDER BY is only allowed in the outermost query or in subqueries that use TOP/LIMIT/FETCH FIRST clauses (not in this question's context).

Multiple choice technology databases
  1. 2

  2. 1

  3. 0

  4. error

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

The LENGTH function in Oracle returns the character count of its argument after converting it to a string. When passed -1, Oracle implicitly converts it to the string '-1', which contains 2 characters: the minus sign and the digit 1. The LENGTH function counts all characters including signs and decimal points. This is not an error - Oracle allows implicit type conversion from number to varchar2.

Multiple choice technology databases
  1. 14

  2. >14

  3. error

  4. <14

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

COUNT(column_name) ignores NULL values and only counts non-NULL entries. With 14 total records and 1 NULL in MGR column, COUNT(MGR) returns 13, which is <14. COUNT(*) would return 14 because it counts all rows regardless of NULLs. The question tests understanding that aggregate functions like COUNT, SUM, AVG skip NULL values when operating on a specific column.

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

A composite primary key involves multiple columns and must be declared using table-level constraint syntax (outside the column definitions). Single-column constraints like NOT NULL, UNIQUE, and CHECK can be declared inline with the column. For example: CREATE TABLE foo (a INT, b INT, PRIMARY KEY (a,b)) - the PRIMARY KEY clause at table level creates a composite key. Inline column syntax cannot specify multiple columns for a single constraint.

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

In Oracle, deferred constraints are validated only at transaction commit time, not after each DML operation. This allows intermediate constraint violations during transaction processing. Option A is incorrect because constraints ARE checked - just deferred. Option C describes behavior for initially deferred vs. immediate constraints. Option D is incorrect because there's no time-interval-based checking.

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.