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
-
Joins
-
Unions
-
Nested SELECT
-
All of the above
D
Correct answer
Explanation
Data can be retrieved from multiple tables using Joins (combining columns), Unions (combining rows), or Nested SELECT queries (subqueries). Therefore, all of the listed methods are correct.
B
Correct answer
Explanation
COL2 is the definition that will cause failure because VARCHAR columns cannot have DEFAULT NONE in DB2. The DEFAULT clause for VARCHAR must specify a valid string value or be omitted entirely. COL1, COL3, and COL4 definitions are syntactically valid.
-
Check constraint
-
Default constraint
-
Unique constraint
-
Informational constraint
C
Correct answer
Explanation
A UNIQUE constraint ensures a column will not accept NULL values (in most DBMS implementations) and creates an index that can be referenced by a foreign key. CHECK constraints only validate data values, DEFAULT constraints provide fallback values, and INFORMATIONAL is not a standard constraint type.
-
ADMIN Privileges
-
CREATETAB Privileges
-
No Privileges
-
USERTAB Privileges
B
Correct answer
Explanation
In DB2 and similar SQL databases, the specific privilege required to create a table is CREATETAB. General administrative privileges are not strictly necessary, and USERTAB is not a valid privilege.
-
It has to be in a CURSOR
-
cannot be used in Embedded SQL
-
No restrictions
-
None of the above
A
Correct answer
Explanation
UNION must be declared within a CURSOR in embedded SQL because embedded SQL requires declared cursors for result set processing. This is a restriction specific to embedded SQL environments where result sets must be explicitly defined.
-
SELECT COUNT *
-
SELECT COUNT(*)
-
SELECT COUNT[*]
-
SELECT COUNT(ALL)
B
Correct answer
Explanation
SELECT COUNT() is the correct SQL syntax for counting all rows in a table. Option A is missing parentheses, C uses incorrect brackets, and D is not valid syntax for counting all rows. COUNT() counts all rows including NULLs.
-
@abcd.sql
-
@abcd
-
get abcd.sql /
-
all the above
B
Correct answer
Explanation
The RUN command in SQL*Plus executes the SQL statements stored in the current buffer. It processes the SQL command and displays the output. The other options (jump, walk, sleep) are not valid SQL*Plus commands.
-
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.
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.