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 programming languages
  1. INSERT

  2. APPEND

  3. COLLECT

  4. GROUP

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

COLLECT inserts rows into an internal table if a line with the same key does not exist, or aggregates (sums) the numeric fields with the existing entry if the key matches. INSERT and APPEND do not aggregate numeric values, and GROUP is used for categorization in loops.

Multiple choice technology programming languages
  1. The number of rows in the internal table

  2. The current OCCURS value

  3. Zero, if the table contains one or more rows

  4. The length of the internal table row structure

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

The DESCRIBE TABLE statement sets the system field SY-TFILL to contain the current number of rows (lines) populated in the internal table. It does not store the OCCURS initialization value, the row structure length, or zero for non-empty tables.

Multiple choice technology web technology
  1. T1

  2. T2

  3. T3 from the dictionary

  4. Cannot be determined

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

A foreign key table is the table that contains the foreign key field being validated. Here, T1 contains field t1-fielda which needs to be validated against the check table T2's field t2-fielda. Therefore T1 is the foreign key table (dependent table) and T2 is the check table.

Multiple choice technology
  1. True

  2. False

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

Most reporting tools and database systems allow users to write their own SQL queries to create custom reports. While some tools have visual report builders, raw SQL access is a standard feature for flexibility and custom data extraction.

Multiple choice technology mainframe
  1. yes/no

  2. invalid values

  3. row not found

  4. all of the above

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

DB2 validation indicators require handling for multiple scenarios: yes/no conditions, invalid values that fail validation, and row-not-found cases when queries return no results. Comprehensive error handling must account for all these possible validation outcomes.

Multiple choice technology mainframe
  1. SELECT CHAR(CAST (tablename.Date_variable AS DATE), ISO

  2. SELECT DATE(tablename.Date_variable, ISO)

  3. SELECT (tablename.Date_variable AS DATE)

  4. ALL OF THEM

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

The correct syntax uses CAST to convert the date variable to DATE format, then CHAR to format it with ISO standard. Options B and C use incorrect syntax, and D cannot be correct since only A follows proper SQL date casting conventions.

Multiple choice technology mainframe
  1. (0000-00-00 and 0000-00-00-00.00.00.000000)

  2. (0001-01-01 and 0001-01-01-01.01.01.000001)

  3. (0001-01-01 and 0001-01-01-00.00.00.000000)

  4. (0001-01-01 and 0000-00-00-00.00.00.000000)

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

In DB2 database systems, when date or timestamp columns have null values, their low-value (minimum) default representations are '0001-01-01' for dates and '0001-01-01-00.00.00.000000' for timestamps. All-zero values are invalid in DB2, and other choices specify incorrect time components.

Multiple choice technology databases
  1. SELECT * FROM emp WHERE empid = 493945;

  2. SELECT empid FROM emp WHERE empid= 493945;

  3. SELECT empid FROM emp;

  4. SELECT empid WHERE empid = 56949 AND lastname = ‘SMITH’;

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

To solve this question, the user needs to know the basic syntax of SQL queries. The user must evaluate each query to identify the one that contains an error.

Now, let's go through each option and explain why it is right or wrong:

A. SELECT * FROM emp WHERE empid = 493945;

This statement is correct. It selects all columns from the "emp" table where the "empid" column has a value of 493945.

B. SELECT empid FROM emp WHERE empid= 493945;

This statement is correct. It selects the "empid" column from the "emp" table where the "empid" column has a value of 493945.

C. SELECT empid FROM emp;

This statement is correct. It selects the "empid" column from the "emp" table without any filtering conditions.

D. SELECT empid WHERE empid = 56949 AND lastname = ‘SMITH’;

This statement contains an error. It is missing the "FROM" keyword, which is required to specify the table from which the data should be selected. The correct statement would be "SELECT empid FROM emp WHERE empid = 56949 AND lastname = 'SMITH'".

Therefore, the answer is:

The Answer is: D

Multiple choice technology databases
  1. percentage sign

  2. Quotation marks

  3. Ampersand

  4. Ellipses

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

To solve this question, the user needs to be aware of the syntax used to specify runtime variables in SQL SELECT statements.

The correct answer is:

C. Ampersand

Explanation: In SQL SELECT statements, runtime variables are specified using the ampersand (&) character followed by the variable name. For example, to specify a variable named "dept_name", you would use "&dept_name" in the SELECT statement. This allows users to enter a value for the variable at runtime, rather than hard-coding the value into the query.

Option A (percentage sign) is incorrect, as this character is commonly used as a wildcard operator in SQL, but not for specifying runtime variables.

Option B (quotation marks) is also incorrect, as quotation marks are used to delimit string literals in SQL, but not for specifying runtime variables.

Option D (ellipses) is incorrect, as ellipses are not used in SQL syntax for specifying runtime variables.

Therefore, the correct answer is:

The Answer is: C. Ampersand

Multiple choice technology databases
  1. No effect

  2. The index will be rendered invalid

  3. The index will be dropped

  4. The index will contain NULL values.

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

When a table is dropped, all indexes associated with that table are automatically dropped as well. This is because indexes are dependent objects that cannot exist without the base table.

Multiple choice technology databases
  1. Names starting with “a”

  2. Names with "a" as second character

  3. Last character as "a"

  4. Names with atleast two "a" at the start.

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

The LIKE pattern '_a%' uses underscore as a single-character wildcard, so it matches names where the second character is 'a'. The percent sign allows any characters after that.

Multiple choice technology mainframe
  1. SELECT DATE(tablename.Date_variable, ISO)

  2. SELECT (tablename.Date_variable AS DATE)

  3. SELECT CHAR(CAST (tablename.Date_variable AS DATE), ISO)

  4. ALL OF THEM

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

In DB2, converting a date field to a specific character string format is done using the CHAR() function with the date value and an optional format identifier like ISO. The syntax CHAR(CAST(column AS DATE), ISO) is syntactically valid and returns the formatted date string.