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. VALUES degf_to_c(32)

  2. SELECT date, degf_to_c(temp) AS temp_c FROM temp_data

  3. CALL degf_to_c(32)

  4. Both a and b

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

The scalar function degf_to_c can be invoked inline within a SELECT statement projection or using a VALUES statement to evaluate the expression. It cannot be invoked using CALL, which is reserved for stored procedures, making 'Both a and b' the correct choice.

Multiple choice technology programming languages
  1. var2 NUMBER := 0;

  2. INTO var2

  3. WHERE name = 'JORDAN';

  4. var1 :=var2 + 2000;

  5. There are no errors in this PL/SQL block

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

The variable var1 is declared as a CONSTANT in the PL/SQL block. Constants cannot have their values reassigned after initialization. The line var1 := var2 + 2000; attempts to modify this constant, which triggers a compilation error.

Multiple choice technology databases
  1. True

  2. False

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

T-SQL (Microsoft SQL Server) variables are case-insensitive. @MyVar and @myvar refer to the same variable. This is consistent with SQL Server's default case-insensitive collation behavior. The only case-sensitive elements in T-SQL are string comparisons (if using a case-sensitive collation) and object names in case-sensitive databases.

Multiple choice technology databases
  1. Index

  2. Sequence

  3. Nickname

  4. View

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

In DB2, SELECT privilege can be granted on tables, views, and nicknames. Nicknames are federated database objects that reference remote data sources and support the same privilege model as local tables. Views are virtual tables that also support SELECT privilege. Indexes are internal structures with no privilege control, and sequences use USAGE or NEXT VALUE privileges, not SELECT.

Multiple choice technology databases
  1. Identity column

  2. Table function

  3. Sequence

  4. Trigger

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

Sequences in DB2 are explicitly referenced in INSERT statements using expressions like NEXT VALUE FOR sequence_name or PREVIOUS VALUE FOR sequence_name to generate unique numeric values for a column. Identity columns are implicitly auto-generated and not externally referenced. Table functions return row sets, not single values. Triggers execute code but don't generate values directly for INSERT.

Multiple choice technology databases
  1. A select operation

  2. An update operation

  3. An insert operation

  4. A delete operation

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

Database triggers are event-driven procedures that fire only on data modification operations: INSERT, UPDATE, and DELETE. SELECT operations query data without modifying it, so they never activate triggers. This is by design since triggers are meant to enforce business rules, audit changes, or maintain referential integrity when data changes.

Multiple choice technology databases
  1. Default constraint

  2. Column data type

  3. Column name

  4. Table name

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

When creating a table, the table name, column names, and column data types are all required - a table cannot exist without them. A default constraint is optional because columns can be created without default values. NULL/NOT NULL is also optional but not listed among the choices.

Multiple choice technology databases
  1. Index

  2. Check constraint

  3. Default constraint

  4. Referential constraint

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

A default constraint only provides a fallback value when no value is specified - it doesn't restrict which values can be inserted. Check constraints restrict values to specific conditions. Referential constraints (foreign keys) restrict values to existing values in another table. Indexes can enforce uniqueness via unique constraints but don't restrict values otherwise.

Multiple choice technology databases
  1. When it is created

  2. When it is referenced in an INSERT statement

  3. Any time an executable SQL statement references it

  4. The first time any executable SQL statement references it

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

Views are virtual tables that don't store data - they execute the underlying query each time they're referenced. A view populates dynamically whenever any executable SQL statement (SELECT, INSERT, UPDATE, DELETE) references it. Views don't cache results and don't populate at creation time.

Multiple choice technology databases
  1. True

  2. False

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

The answer is False because while rowid provides fast access, it's not recommended as a primary key in NPS. Rowids can change during operations like DELETE and INSERT, making them unreliable as permanent identifiers. Best practice is to use explicit surrogate keys or natural keys that remain stable. Rowid is useful for performance but not as a primary key.

Multiple choice technology databases
  1. True

  2. False

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

The statement is False because NPS doesn't support this ALTER TABLE syntax. NPS has limited ALTER TABLE capabilities and doesn't allow adding columns with this syntax. In NPS, you typically need to recreate the table to add columns. The statement looks like SQL from other databases but doesn't work in NPS.

Multiple choice technology databases
  1. single quote

  2. semicolon

  3. double quote

  4. colon

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

The semicolon is the standard SQL command terminator in nzsql (Netezza's SQL interface, similar to PostgreSQL). It signals to the SQL parser that the command is complete and ready for execution. Quotes are for string literals, not command termination.