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

  2. 3

  3. N - 1

  4. N + 1

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

To solve this question, the user needs to have a basic understanding of SQL joins and how to prevent cartesian products.

When joining N tables, the minimum number of conditions that should appear in the WHERE clause to produce a meaningful result set without any cartesian products is N - 1. This is because each join condition connects two tables, and N tables can be connected by N - 1 join conditions.

Option A (4) and Option B (3) are not correct because they provide specific numbers of conditions that do not apply to all cases. The number of conditions needed depends on the number of tables being joined, which is not specified in the question.

Option C (N - 1) is correct, as explained above.

Option D (N + 1) is incorrect because adding an additional condition would result in a more restrictive query, potentially excluding valid results.

Therefore, the answer is: C. N - 1.

Multiple choice technology databases
  1. Primary key access

  2. Access via unique index

  3. Table access by ROWID

  4. Full table scan

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

ROWID provides the fastest access because it contains the exact physical address of the row in the database file (data block, row position). Primary key access and unique index access require index traversal first, then table access. Full table scan reads every row, making it the slowest method.

Multiple choice technology databases
  1. DROP

  2. DELETE

  3. CASCADE

  4. TRUNCATE

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

To solve this question, the user needs to know the basic SQL commands for deleting data from a table.

Option A: DROP is used to delete an entire table, not just its data. This option is incorrect.

Option B: DELETE is used to delete data from a table. However, it writes the deleted data to the rollback segment in case it needs to be recovered later. This option is incorrect.

Option C: CASCADE is an option used with the DROP command to delete all objects that depend on the specified object before dropping that object. This option is incorrect.

Option D: TRUNCATE is used to delete all data from a table without logging the individual row deletions. It does not write the deleted data to the rollback segment, making it a faster operation compared to DELETE. This option is correct.

Therefore, the answer is: D. TRUNCATE.

Multiple choice technology databases
  1. ENCRYPT

  2. DECRYPT

  3. WRAP

  4. UNWRAP

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

The WRAP command is used to encrypt PL/SQL source code. It obfuscates the code by converting it to a format that's not human-readable but remains executable. This protects intellectual property while allowing the database to execute the code. ENCRYPT, DECRYPT, and UNWRAP are not valid PL/SQL commands.

Multiple choice technology databases
  1. HAVING clause

  2. ORDER BY clause

  3. Subquery

  4. GROUP BY clause

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

A subquery can be embedded in a WHERE clause to provide search criteria for the main SELECT statement. HAVING filters grouped results after aggregation, ORDER BY only sorts the output, and GROUP BY organizes data for aggregation - none of these provide search criteria.

Multiple choice technology databases
  1. MAXVALUE

  2. MINVALUE

  3. CYCLE

  4. INCREMENT BY

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

The CYCLE clause causes a sequence to automatically restart from MINVALUE when MAXVALUE is reached (or from MAXVALUE when MINVALUE is reached for descending sequences). MAXVALUE sets the upper limit, MINVALUE sets the lower limit, and INCREMENT BY defines the step between values.

Multiple choice technology databases
  1. USER_CONSTRAINTS

  2. USER_CONS_COLUMNS

  3. DBA_CONSTRAINTS

  4. DBA_TABLE

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

USER_CONS_COLUMNS displays information about columns that participate in constraints. USER_CONSTRAINTS shows constraint definitions but not column-level details. DBA_CONSTRAINTS is the DBA-wide view, and DBA_TABLE doesn't exist (should be DBA_TABLES).

Multiple choice technology security
  1. True

  2. False

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

SQL injection is possible because despite using PreparedStatement, the code concatenates username and password directly into the query string instead of using parameter placeholders (?). The vulnerability is in the statement: "...where username="+username+" and password="+password. An attacker could input ' OR '1'='1 as password to bypass authentication. PreparedStatement only prevents SQLi when used with setString() on placeholders.

Multiple choice technology databases
  1. 17000.00

  2. 17000*****

  3. **17000.00

  4. An error statement

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

LPAD(salary,10,*) will fail because * is not a valid padding character - it's a SQL wildcard character that has special meaning. The LPAD function expects a literal character string for padding, not a metacharacter. This causes an error regardless of salary value. LPAD would pad to length 10 with the specified character if valid.