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 programming languages
  1. By using the insert="false" and update="false" attributes.

  2. By using the isinsert="false" and isupdate="false" attributes

  3. By using the isinsert="no" and isupdate="no" attributes.

  4. None

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

To make a property read-only from Hibernate's perspective (modifiable only by the database, not through the session), use insert="false" and update="false". This tells Hibernate to include the field in SELECT queries but not in INSERT or UPDATE operations.

Multiple choice technology programming languages
  1. Session.load();

  2. Session.get();

  3. Session.fetch();

  4. None of the above

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

When a row might not exist, Session.get() is preferred because it returns null if not found. Session.load() throws an ObjectNotFoundException if the row doesn't exist, and it returns a proxy which can cause issues if the object doesn't actually exist.

Multiple choice technology programming languages
  1. Bag has index column

  2. Bag permits duplicate element values

  3. Bag does not permits duplicate element values

  4. None

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

In Hibernate, a Bag is an unordered collection that allows duplicate elements, mapped using a java.util.Collection. Unlike a List or an Array, a Bag does not maintain an index column, making the second option correct and the first and third options incorrect.

Multiple choice technology programming languages
  1. lazy=false;

  2. lazy=true;

  3. lazy=yes;

  4. lazy=no;

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

In Hibernate 3 and later, lazy loading is enabled by default (lazy="true") for collections and associations to optimize application performance and prevent loading unnecessary data from the database. The alternatives like lazy=false are not default settings, and options using 'yes' or 'no' are syntactically invalid.

Multiple choice technology programming languages
  1. By auditing the all DML operations on table.

  2. By using external table

  3. By using triggers.

  4. By using anonymous PL/SQL blocks

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

To achieve the given objective, you can use triggers, which are special PL/SQL programs that are automatically executed in response to specific DML events.

Option A: Auditing the DML operations on the table would provide information about who performed the transactions, but it would not capture the values used in the transactions. Additionally, the auditing information may not be easily transferable to another table for analysis.

Option B: Using an external table would not help in tracking users who performed the transactions and the values used in the transactions. External tables are used to map data in flat files into database tables, or to query data in external sources as if it were in a table. They are not designed for capturing transaction details.

Option C: Using triggers would help you track the users who performed the transactions and the values used in the transactions. You can create a trigger to automatically insert a row into another table, such as an audit table, when a DML operation occurs on the original table. The inserted row can contain information such as the user who performed the transaction, the type of transaction (insert, update, or delete), the date and time of the transaction, and the values used in the transaction. This information can be used for analysis and to detect unauthorized activity.

Option D: Using anonymous PL/SQL blocks would not help in tracking users who performed the transactions and the values used in the transactions. Anonymous PL/SQL blocks are used to execute a sequence of SQL and PL/SQL statements and are not designed for capturing transaction details.

Therefore, the correct option is:

The Answer is: C. By using triggers.

Multiple choice technology databases
  1. 1/1/0051

  2. 1/1/1951

  3. 1/1/2051

  4. 1/1/9951

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

In Oracle SQL, the YY format specifier interprets two-digit years within a sliding window. The year '51' with YY format defaults to 2051 (current century for years 50-99). The RR format uses a different sliding window based on the current year, but YY simply uses the current century boundary.

Multiple choice technology databases
  1. 1/1/2051

  2. 1/1/1951

  3. 1/1/0051

  4. 1/1/9951

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

Oracle's RR format uses a sliding window: if the last two digits of the current year are 00-49, then years 00-49 map to current century and 50-99 map to previous century. Assuming current year context where '51' falls in the 50-99 range, it maps to 1951. This is different from YY which would give 2051.

Multiple choice technology databases
  1. True

  2. False

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

When the input year is '99', YY and RR formats give different results. YY interprets '99' as 2099 (current century), while RR's sliding window maps '99' to 1999 (previous century, assuming current year is in 00-49 range). Therefore, the outputs are NOT the same.

Multiple choice technology databases
  1. True

  2. False

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

For year '00', both YY and RR formats resolve to 2000 when the current year is in the 00-49 range. RR's sliding window maps 00-49 to the current century, and YY also maps to current century. Thus, both queries produce the same output.

Multiple choice technology databases
  1. Error: invalid identifier

  2. Error : Invalid Character

  3. NULL

  4. #

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

When '#' is enclosed in single quotes, Oracle treats it as a string literal, not a comment symbol. The query SELECT '#' FROM dual simply returns the character '#' as a string value. No error occurs because it's properly quoted.

Multiple choice technology databases
  1. Error : Invalid Character

  2. Error : Invalid identifier

  3. #

  4. NULL

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

When '#' appears without quotes in a SELECT statement, Oracle interprets it as the start of a comment. Since a comment requires valid syntax or continues to end of line, this causes an 'Invalid Character' error. The '#' character is not a valid token outside string literals.

Multiple choice technology databases
  1. 1 row

  2. NULL

  3. 30 rows

  4. 3 rows

  5. 2 rows

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

ROWNUM is a pseudo-column assigned to rows as they are retrieved. In Oracle, ROWNUM values start from 1, and ROWNUM <= 3 will return the first 3 rows. The BETWEEN 0 AND 3 condition effectively filters for ROWNUM <= 3, returning exactly 3 rows from the 30-row table.

Multiple choice technology databases
  1. 1 row

  2. NULL

  3. 0 row

  4. 3 rows

  5. 30 rows

  6. 2 rows

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

ROWNUM conditions have special behavior. ROWNUM IN (1,3) only matches the first row because ROWNUM = 1 is true for the first row, but when checking ROWNUM = 3, the third row never gets ROWNUM = 3 (it fails at 1 or 2). Only the first row satisfies ROWNUM = 1, so exactly 1 row is returned.