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 web technology
  1. criteria.setOrder( Order.asc("name") )

  2. criteria.add( Order.asc("name") )

  3. criteria.addOrder( Order.asc("name") )

  4. criteria.addOrder( "name asc" )

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

The Hibernate Criteria API uses addOrder() method to add sorting, not setOrder() or add(). The method takes an Order object like Order.asc("name") or Order.desc("name").

Multiple choice technology web technology
  1. sess.createQuery("SELECT * FROM CATS").list();

  2. sess.createSQLQuery("FROM CATS").list();

  3. sess.createSQLQuery("SELECT * FROM CATS").list();

  4. sess.createSQLQuery("from CATS", com.animals.Cat.class).list();

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

Native SQL queries in Hibernate are executed using createSQLQuery() method which accepts raw SQL strings. Option C uses the correct syntax. Option A uses HQL (createQLQuery), Option B uses incorrect SQL, and Option D incorrectly mixes HQL syntax with SQL.

Multiple choice technology web technology
  1. integer

  2. character

  3. yes_no

  4. None of the above

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

Hibernate basic value types include integer, character, yes_no (boolean mapping), string, date, and many others. Since all options A, B, C are valid basic types, the correct answer is 'None of the above' (meaning none is NOT a basic type).

Multiple choice technology programming languages
  1. Check whether cursor has fetched any row

  2. Check whether cursor has not fetched any row.

  3. Check the number of rows returned by the cursor

  4. Both A and C

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

%ROWCOUNT is a cursor attribute that returns the number of rows fetched by the cursor so far. It is a numeric value that increments with each successful fetch operation.

Multiple choice technology programming languages
  1. open cursor; ---some statements close;

  2. open cursor; fetch into variables; ---some statements close cursor;

  3. open cursor; fetch into variables; ---some statements close;

  4. All of the above

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

The correct structure of an explicit cursor is: OPEN cursor, FETCH cursor INTO variables, process the data, then CLOSE cursor. Option B correctly shows this complete lifecycle with FETCH statement included.

Multiple choice technology databases
  1. You obtain the results retrieved from the public synonym HR created by the DBA.

  2. You obtain the results retrieved from the HR table that belongs to you schema.

  3. You get an error message because you cannot retrieve from a table that has the same name as a public synonym.

  4. You obtain the results retrieved from both the publich synonym HR and the HR table that belongs to your schema, as a Cartesian product.

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

In Oracle database name resolution, when a reference is ambiguous (could refer to a local object or a public synonym), the local schema objects take precedence. Your own HR table in your schema will be accessed instead of the public synonym HR that points to GENERAL.HUMAN_RESOURCES.

Multiple choice technology databases
  1. A view can be created as read only.

  2. A view can be created as a join of two or more tables.

  3. A view can not have an ORDER BY clause in the SELECT statement.

  4. A view can not be created with a GROUP BY clause in the SELECT statement.

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

SQL views can be created with the WITH CHECK OPTION to make them read-only, preventing inserts or updates through the view. Views can also be created as joins of two or more tables to present combined data. However, standard SQL prohibits ORDER BY in view definitions - ordering belongs in queries accessing the view. Views can use GROUP BY for aggregation.

Multiple choice technology databases
  1. A main query can have mroe than one subquery.

  2. A subquery can have more than one main query.

  3. The sub query and main query must retrieve data from the same table.

  4. The subquery and main query can retrieve data from different tables.

  5. Only one column or expression can be compared between the subquery and main query.

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

A main query can indeed contain multiple subqueries in different clauses (WHERE, FROM, SELECT). Subqueries and main queries can access entirely different tables - they're independent queries. When comparing a subquery result to the main query in a WHERE clause, only one column or expression can be compared (this is the scalar subquery pattern). Option B is false because a subquery is nested within one main query, not multiple.

Multiple choice technology mainframe
  1. For Renames Clause

  2. For Condition Names

  3. Elementary level item. Cannot be subdivisions of other items (cannot be qualified), nor can they be subdivided themselves.

  4. All of the above

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

Level 66 is specifically used for the RENAMES clause in COBOL. It allows you to regroup existing data elements by giving a new name to a contiguous set of elementary items. Level 88 is for condition names, and level 77 is for independent elementary items.