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. SELECT * FROM Persons WHERE FirstName='%a%'

  2. SELECT * FROM Persons WHERE FirstName='a'

  3. SELECT * FROM Persons WHERE FirstName LIKE '%a'

  4. SELECT * FROM Persons WHERE FirstName LIKE 'a%'

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

The SQL LIKE operator with wildcards is used for pattern matching. The '%' wildcard matches any sequence of characters. To match names starting with 'a', use 'a%' where 'a' matches the first character and '%' matches any following characters. Option D correctly uses: 'SELECT * FROM Persons WHERE FirstName LIKE 'a%'. Option A ('%a%') matches names containing 'a' anywhere. Option B uses exact equality instead of pattern matching. Option C ('%a') matches names ending with 'a'.

Multiple choice technology databases
  1. SELECT * FROM Persons WHERE FirstName='Peter',LastName='Jackson'

  2. SELECT * FROM Persons WHERE FirstName='Peter' OR LastName='Jackson'

  3. SELECT * FROM Persons WHERE FirstName='Peter' AND LastName='Jackson'

  4. SELECT * FROM Persons WHERE FirstName<>'Peter' AND LastName<>'Jackson'

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

To filter results based on multiple criteria that must all be met, the SQL AND operator is used. Using a comma in a WHERE clause is syntactically incorrect, and the OR operator would return records matching either name, not necessarily both.

Multiple choice technology databases
  1. SELECT * FROM Persons ORDER BY FirstName DESC

  2. SELECT * FROM Persons SORT BY 'FirstName' DESC

  3. SELECT * FROM Persons SORT 'FirstName' DESC

  4. SELECT * FROM Persons ORDER FirstName DESC

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

To sort results in SQL, use the ORDER BY clause followed by ASC (ascending) or DESC (descending). For descending order by FirstName, the correct syntax is 'ORDER BY FirstName DESC'. Option A correctly uses: 'SELECT * FROM Persons ORDER BY FirstName DESC'. Options B and C incorrectly use 'SORT' instead of 'ORDER BY'. Option D is missing the 'BY' keyword after ORDER.

Multiple choice technology databases
  1. SELECT DIFFERENT

  2. SELECT DISTINCT

  3. SELECT COUNT

  4. SELECT UNIQUE

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

SELECT DISTINCT returns only unique (different) values from the specified columns, eliminating duplicate rows. SELECT DIFFERENT and SELECT UNIQUE are not valid SQL syntax. SELECT COUNT returns the count of rows, not distinct values.

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.