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. Blank removed Column_name1, first 5 character of column_name2,2 to 4 character part of string from Column_name3

  2. Blank removed Column_name1, last 5 character of column_name2,2 to 4 character part of string from Column_name3

  3. Blank removed Column_name1, first 5 character of column_name2 and 2,3,4,5 character part of string from Column_name3

  4. None of the above

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

The TRIM function removes leading and trailing blanks from column_name1. LEFT(column_name2,5) returns the first 5 characters from the left side. SUBSTRING(column_name3,2,4) extracts 4 characters starting from position 2, which gives characters at positions 2, 3, 4, and 5. Option A incorrectly states '2 to 4 character part' when it should be 4 characters starting from position 2.

Multiple choice technology databases
  1. 1

  2. 3

  3. 2

  4. None of the above

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

The @@sqlstatus system variable in Sybase returns specific status codes: 0 for successful completion, 1 for an error occurring during execution, and 2 for a data truncation warning. The value 3 is not a valid return value for @@sqlstatus. Option D is incorrect because option B (3) is indeed not a possible value.

Multiple choice technology databases
  1. End case

  2. When

  3. then

  4. None of the above

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

In Sybase CASE statements, the valid keywords are CASE, WHEN, THEN, ELSE, and END. 'End case' as two words is not the correct syntax - the proper keyword is just 'END' (or 'END CASE' is sometimes used but 'END' alone terminates the CASE). The question correctly identifies that 'End case' as a phrase is not part of the CASE keyword structure.

Multiple choice technology databases
  1. Current_date

  2. Datachange

  3. Gettime

  4. Convert

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

CURRENT_DATE is a valid Sybase date function. DATACHANGE (or DATECHANGE) exists in Sybase for tracking data modifications. CONVERT is a standard Sybase function for data type conversion. GETTIME() is not a standard Sybase function - the correct function is GETDATE() which returns both date and time. Sybase does not have a GETTIME() function.

Multiple choice technology databases
  1. 250

  2. 255

  3. 2065

  4. 1026

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

In older versions of Sybase, the maximum number of indexes per user table was 250 (one clustered index plus 249 non-clustered indexes). This limit was increased in later versions. Option B (255) is close but not the standard limit for these older versions. The other values (2065, 1026) are not standard Sybase index limits. This is version-specific knowledge.

Multiple choice technology databases
  1. True

  2. False

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

You can add constraints to existing tables using ALTER TABLE, but you add constraints to existing columns, not by creating new columns. The statement claims constraints are added 'by creating new column' which is not correct - constraints are added to columns that already exist. You can also add new columns WITH constraints, but the constraint itself is not created by adding a column. The statement is false.

Multiple choice technology databases
  1. Strong Question Language

  2. Structured Query Language

  3. Structured Question Language

  4. None of the Above

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

SQL stands for Structured Query Language, the standard language for relational database operations like querying, updating, and managing data in RDBMS systems.

Multiple choice technology databases
  1. UNION only selects distinct values, UNION ALL selects all values (excluding ?duplicates)?

  2. UNION ALL only selects distinct values, UNION selects all values (including ?duplicates)?

  3. UNION only selects distinct values, UNION ALL selects all values (including ?duplicates)?

  4. UNION ALL only selects distinct values, UNION selects all values (excluding ?duplicates)?

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

UNION removes duplicate rows from the combined result set, while UNION ALL keeps all rows including duplicates. UNION ALL is faster because it skips the duplicate elimination step.

Multiple choice technology databases
  1. 10

  2. 1

  3. 5

  4. 50

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

For a non-correlated subquery (the standard case implied by the wording), the subquery executes once and returns its result set to be used by the main query. The main query then filters its 10 records using the 5 records from the subquery. Only a correlated subquery would execute once per main query row (10 times), but the question does not specify correlation.

Multiple choice technology databases
  1. WHERE

  2. HAVING

  3. HAVING BY

  4. ORDER BY

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

The HAVING clause is specifically designed to filter groups after the GROUP BY operation has aggregated the data. The WHERE clause filters individual rows before grouping, which is why it cannot be used with aggregate functions. HAVING BY and ORDER BY are not filtering clauses for grouped data.

Multiple choice technology databases
  1. Delete

  2. Truncate

  3. Insert

  4. Update

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

TRUNCATE is a DDL (Data Definition Language) operation that bypasses the transaction log and does not fire triggers. DELETE, INSERT, and UPDATE are DML (Data Manipulation Language) operations that respect triggers. This is why TRUNCATE is faster but also riskier - you cannot roll it back or trigger cleanup logic.