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
-
criteria.setOrder( Order.asc("name") )
-
criteria.add( Order.asc("name") )
-
criteria.addOrder( Order.asc("name") )
-
criteria.addOrder( "name asc" )
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").
-
sess.createQuery("SELECT * FROM CATS").list();
-
sess.createSQLQuery("FROM CATS").list();
-
sess.createSQLQuery("SELECT * FROM CATS").list();
-
sess.createSQLQuery("from CATS", com.animals.Cat.class).list();
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.
-
commit()
-
flush()
-
close()
-
list()
B
Correct answer
Explanation
The flush() method synchronizes the session state with the database, executing all pending SQL statements. commit() commits the transaction, close() closes the session, and list() returns query results. flush() is what actually ensures SQL execution.
-
integer
-
character
-
yes_no
-
None of the above
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).
-
echo_sql
-
show_sql
-
print_sql
-
display_sql
B
Correct answer
Explanation
Hibernate uses the 'show_sql' property to print all executed SQL statements to the console. This is a boolean configuration property that enables SQL logging for debugging purposes.
-
Check whether cursor has fetched any row
-
Check whether cursor has not fetched any row.
-
Check the number of rows returned by the cursor
-
Both A and C
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.
-
user defined
-
implied
-
implicit and explicit
-
Implied and user defined
C
Correct answer
Explanation
PL/SQL has two types of cursors: implicit cursors (automatically created by Oracle for SQL statements) and explicit cursors (explicitly declared and managed by the programmer).
-
open cursor; ---some statements close;
-
open cursor; fetch into variables; ---some statements close cursor;
-
open cursor; fetch into variables; ---some statements close;
-
All of the above
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.
-
NUMBER
-
BOOLEAN
-
CHARACTER
-
STRING
B
Correct answer
Explanation
The %FOUND cursor attribute returns a BOOLEAN value (TRUE if a row was fetched, FALSE if not). It does not return NUMBER, CHARACTER, or STRING types.
A
Correct answer
Explanation
The default parameter mode for procedures is IN. IN parameters pass values into the procedure but cannot be modified within the procedure.
-
IN
-
IN, OUT
-
IN, OUT,INOUT
-
IN, OUT, INOUT , OUTIN
C
Correct answer
Explanation
Procedures accept three parameter modes: IN (read-only input), OUT (write-only output), and INOUT (read and write). These modes control how data flows between the procedure and calling environment.
-
You obtain the results retrieved from the public synonym HR created by the DBA.
-
You obtain the results retrieved from the HR table that belongs to you schema.
-
You get an error message because you cannot retrieve from a table that has the same name as a public synonym.
-
You obtain the results retrieved from both the publich synonym HR and the HR table that belongs to your schema, as a Cartesian product.
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.
-
A view can be created as read only.
-
A view can be created as a join of two or more tables.
-
A view can not have an ORDER BY clause in the SELECT statement.
-
A view can not be created with a GROUP BY clause in the SELECT statement.
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.
-
A main query can have mroe than one subquery.
-
A subquery can have more than one main query.
-
The sub query and main query must retrieve data from the same table.
-
The subquery and main query can retrieve data from different tables.
-
Only one column or expression can be compared between the subquery and main query.
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.
-
For Renames Clause
-
For Condition Names
-
Elementary level item. Cannot be subdivisions of other items (cannot be qualified), nor can they be subdivided themselves.
-
All of the above
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.