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
-
soundex
-
lightex
-
weightex
-
lux
A
Correct answer
Explanation
SOUNDEX is a SQL function that converts strings to their phonetic representation. It enables finding words that sound similar but have different spellings, which is useful for name matching. The other options (lightex, weightex, lux) are not standard SQL functions.
A
Correct answer
Explanation
FLOOR is a valid Oracle SQL function that returns the largest integer less than or equal to a given number. For example, FLOOR(5.7) returns 5. The other options (window, door, ground) are not standard SQL functions in Oracle.
-
integer
-
character
-
yes_no
-
None of the above
D
Correct answer
Explanation
In Hibernate, integer, character, and yes_no are all valid built-in basic value types. Since all of the listed options are valid basic types, 'None of the above' is the correct choice.
-
commit()
-
flush()
-
close()
-
list()
B
Correct answer
Explanation
The flush() method forces Hibernate to synchronize the in-memory state of the session with the underlying database by executing the necessary SQL statements (INSERT, UPDATE, DELETE) immediately, without committing the transaction.
-
echo_sql
-
show_sql
-
print_sql
-
display_sql
B
Correct answer
Explanation
The 'show_sql' property in Hibernate configuration enables logging of all executed SQL statements to the console. This is essential for debugging and understanding what SQL queries Hibernate generates. Other properties like echo_sql, print_sql, and display_sql are not standard Hibernate configuration properties.
-
criteria.setOrder( Order.asc("name") )
-
criteria.add( Order.asc("name") )
-
criteria.addOrder( Order.asc("name") )
-
criteria.addOrder( "name asc" )
C
Correct answer
Explanation
In Hibernate's Criteria API, the addOrder() method is used to apply sorting to the query results, passing an Order object such as Order.asc("name"). The methods setOrder and add are incorrect for this purpose.
-
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
In Hibernate, createSQLQuery is used to execute native SQL queries. The correct syntax to fetch all records from a table using a native SQL query is sess.createSQLQuery("SELECT * FROM CATS").list(). HQL syntax is used in createQuery.
B
Correct answer
Explanation
SQL's ORDER BY clause can use column aliases defined in the SELECT statement. The aliases are created when SELECT processes the columns, making them available to ORDER BY in the same query level. This makes queries more readable by allowing descriptive names instead of expressions or column positions.
A
Correct answer
Explanation
SQL's ORDER BY clause defaults to ascending (ASC) order when no sort direction is explicitly specified. This means numbers sort from lowest to highest, dates from earliest to latest, and text alphabetically. To reverse this behavior, you must explicitly specify the DESC keyword.
A
Correct answer
Explanation
In SQL, NULL values are treated as the lowest possible values in sorting operations. When using ORDER BY with DESC (descending), NULL values appear first at the top of the result set. This behavior is consistent across most major database systems, though some databases provide options to control NULL positioning in sort order.
-
any outer join
-
left outer join
-
cross join
-
right outer join
D
Correct answer
Explanation
A RIGHT OUTER JOIN returns all rows from the right table (B) and matching rows from the left table (A), with NULL for non-matching left-side rows. LEFT OUTER JOIN would return all from A, CROSS JOIN is a Cartesian product, and ANY OUTER JOIN isn't valid SQL syntax.
-
CASCADE
-
CONSTANT
-
CHECK
-
NONUNIQUE
C
Correct answer
Explanation
CHECK is a valid Oracle constraint that enforces domain integrity by limiting values to a Boolean condition. CASCADE is an action (not a constraint type), CONSTANT isn't an Oracle constraint, and NONUNIQUE isn't a valid constraint (though it describes an index type). Oracle supports PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, and CHECK constraints.
-
DESCRIBE
-
RENAME
-
DELETE
-
INSERT
A
Correct answer
Explanation
DESCRIBE is an iSQL*Plus command that displays the structure of a table or other database object. RENAME, DELETE, and INSERT are SQL statements (DDL/DML), not iSQL*Plus-specific commands. DESCRIBE can be abbreviated as DESC and provides column names, data types, and constraints.
B
Correct answer
Explanation
MERGE is a DML (Data Manipulation Language) statement that combines insert and update operations based on a condition. DROP and CREATE are DDL (Data Definition Language), and COMMIT is a transaction control statement. DML includes SELECT, INSERT, UPDATE, DELETE, and MERGE.
-
National Language Set
-
International Language Set
-
Oracle Language Set
-
SQL-99 compliant Language Set
A
Correct answer
Explanation
National Language Support (NLS) parameters in Oracle are used to customize the display of date, time, currency, and language settings. International, Oracle, and SQL-99 compliant Language Sets are not standard terms for configuring these display formats.