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

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

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

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

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

The SQL LIKE operator is used for pattern matching in string columns. The percent sign (%) is a wildcard that matches zero or more characters. To find values starting with 'a', use 'a%' (matches 'a' followed by anything). Option A ('%a') finds values ending with 'a', option B uses equality instead of pattern matching, and option D has incorrect wildcard placement.

Multiple choice technology web technology
  1. You want all unmatched data from both table

  2. You want all matched data from both table

  3. You want all matched and unmatched data from both table

  4. You want all unmatched data from one table

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

A FULL OUTER JOIN returns all records when there is a match in either the left or the right table records, effectively combining all matched and unmatched rows from both tables.

Multiple choice technology web technology
  1. A view can be created as a join on two or more tables

  2. A view can't be created as a join on two or more tables

  3. A view can't have an ORDER BY clause in SELECT statement

  4. A view can't be created with a GROUP BY clause in SELECT statement

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

Views CAN be created as joins across multiple tables - this is a common use case for simplifying complex queries. Views can also include ORDER BY in some databases (with limitations), and GROUP BY is standard. Option A is correct. Option B directly contradicts A. Options C and D are false - views can include ORDER BY (with TOP/LIMIT in some DBs) and definitely support GROUP BY.

Multiple choice technology web technology
  1. View dropped also

  2. View becomes invalid

  3. View remains as it is

  4. View is accessible

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

When a base table is dropped, any dependent view becomes invalid because its underlying schema no longer exists. The view object isn't automatically dropped (it remains in metadata with an INVALID status). Attempts to query the invalid view will fail. The view must be recreated or the table restored to make it functional again.

Multiple choice technology web technology
  1. UPDATE

  2. ALTER

  3. INSERT

  4. CREATE

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

The UPDATE statement is used to modify existing records in a table, making it the correct command to update a married employee's last name. In contrast, ALTER modifies the table's structure (schema), INSERT adds new records, and CREATE is used to instantiate new database objects like tables.

Multiple choice technology
  1. DIFFERENT

  2. DISTINCT

  3. UNIQUE

  4. ALL

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

The DISTINCT keyword in SQL eliminates duplicate rows from query results, returning only unique values. Option A (DIFFERENT) is not valid SQL syntax. UNIQUE is a constraint, not a query keyword for filtering duplicates. ALL returns all rows including duplicates (default behavior).

Multiple choice technology
  1. SELECT COLUMNS(*) FROM Persons

  2. SELECT COUNT() FROM Persons

  3. SELECT COUNT(*) FROM Persons

  4. SELECT COLUMNS() FROM Persons

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

COUNT(*) is the standard SQL aggregate function that returns the total number of rows in a table, including NULL values. Option A uses non-existent COLUMNS function. Option B has empty COUNT() syntax - needs an argument like * or column name. Option D repeats the COLUMNS error.

Multiple choice technology
  1. NVL

  2. COUNT

  3. CASE

  4. MAX

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

NVL (or COALESCE in standard SQL) substitutes a replacement value when NULL is encountered. NVL(expr, replacement) returns 'replacement' if 'expr' is NULL, otherwise returns 'expr'. COUNT counts rows, CASE is conditional logic, and MAX finds maximum values - none of these handle NULL substitution.

Multiple choice technology
  1. True

  2. False

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

When tables share the same distribution key and are joined on that key, matching rows are already on the same SPU due to hash distribution. This collocated join eliminates the need for data redistribution across SPUs, making the join highly efficient. It's a key performance optimization in MPP databases like Netezza that avoids expensive data movement.