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
A
Correct answer
Explanation
The || operator concatenates strings in SQL. The entire expression address1||','||address2||','||address2 is treated as a single column with the alias 'Adress'. No matter how many columns or literals you concatenate, the result is always one column in the output.
-
Primary key access
-
Access via unique index
-
Table access by ROWID
-
Full table scan
C
Correct answer
Explanation
Retrieving a single row by its physical address (ROWID) is the fastest possible access path in Oracle, as it bypasses index lookups and directly targets the block containing the row.
C
Correct answer
Explanation
To avoid cartesian products when joining n tables, you need at least n-1 join conditions in the WHERE clause. This ensures each new table is linked to the previous ones in a chain. For 4 tables, you need 4-1 = 3 conditions.
-
03-JUL-00
-
10-JUL-00
-
12-JUL-00
-
11-JUL-00
-
17-JUL-00
E
Correct answer
Explanation
To solve this question, the user needs to understand the function of each element of the SQL statement and how it affects the output.
The SQL statement is selecting a date and formatting it according to the given format string. Specifically:
sysdate returns the current date and time.
NEXT_DAY(sysdate, 'MONDAY') returns the next occurrence of the day specified as the second argument, after the current date and time (sysdate). In this case, it returns the next Monday after 10 July 2000, which is 17 July 2000.
to_char() converts the resulting date into a string using the format specified as the second argument. In this case, the format is 'DD-MON-RR', which returns the day of the month (DD), the abbreviated month name (MON), and the 2-digit year (RR).
Therefore, the correct answer is E. 17-JUL-00, as the SQL statement returns the formatted date of the next Monday after 10 July 2000, which is 17 July 2000.
C
Correct answer
Explanation
In SQL*Plus, the hyphen (-) character is used as a continuation character when a SQL statement spans multiple lines. The asterisk (*) is for comments, forward slash (/) executes the buffer, and (@) runs script files.
-
select * from EMP where nvl(EMPNO, '00000') = '59384'
-
select * from EMP where EMPNO = '59384'
-
select EMPNO, LASTNAME from EMP where EMPNO = '59384'
-
select 1 from EMP where EMPNO = '59834'
A
Correct answer
Explanation
The NVL function wraps the indexed column EMPNO, which prevents Oracle from using the index on EMPNO. When a function is applied to a column in the WHERE clause, the index on that column cannot be used unless a function-based index exists. Options B, C, and D directly compare EMPNO, allowing index usage.
-
DROP
-
DELETE
-
CASCADE
-
TRUNCATE
D
Correct answer
Explanation
The TRUNCATE command is a DDL operation that quickly deletes all rows from a table without logging individual row deletions in the rollback segment, unlike DELETE which writes to rollback.
-
Column
-
1966_Invoices
-
Catch_#22
-
#Invoices
-
None of the above
-
5392845.324
-
871039453.1
-
97234512.123
-
1234567.12
B
Correct answer
Explanation
NUMBER(10,2) means total 10 digits with 2 after decimal, so max 8 digits before decimal (10-2=8). Option B has 9 digits before the decimal (871039453), which exceeds the allowed precision and causes an error. Option C has 3 decimal places but only 8 integer digits, so it would round to 97234512.12 without error. Oracle rounds values that exceed scale but fits within precision, only errors when integer part exceeds allowed digits.
-
where
-
having
-
order by
-
none of the above
C
Correct answer
Explanation
Subqueries in SQL cannot use ORDER BY clause because subqueries return a set of rows used by the outer query, and the outer query determines the final ordering. However, subqueries can use WHERE for row filtering and HAVING for group filtering. ORDER BY is only allowed in the outermost query or in subqueries that use TOP/LIMIT/FETCH FIRST clauses (not in this question's context).
A
Correct answer
Explanation
The LENGTH function in Oracle returns the character count of its argument after converting it to a string. When passed -1, Oracle implicitly converts it to the string '-1', which contains 2 characters: the minus sign and the digit 1. The LENGTH function counts all characters including signs and decimal points. This is not an error - Oracle allows implicit type conversion from number to varchar2.
D
Correct answer
Explanation
COUNT(column_name) ignores NULL values and only counts non-NULL entries. With 14 total records and 1 NULL in MGR column, COUNT(MGR) returns 13, which is <14. COUNT(*) would return 14 because it counts all rows regardless of NULLs. The question tests understanding that aggregate functions like COUNT, SUM, AVG skip NULL values when operating on a specific column.
-
Composite primarykey
-
Not null
-
unique
-
check
A
Correct answer
Explanation
A composite primary key involves multiple columns and must be declared using table-level constraint syntax (outside the column definitions). Single-column constraints like NOT NULL, UNIQUE, and CHECK can be declared inline with the column. For example: CREATE TABLE foo (a INT, b INT, PRIMARY KEY (a,b)) - the PRIMARY KEY clause at table level creates a composite key. Inline column syntax cannot specify multiple columns for a single constraint.
-
The Constraint condition is never checked
-
The Constraint condition is checked only at the time of commiting the transaction
-
The Constraint condition is checked only for newly inserted rows and will not be checked for already existing rows in the table
-
The constraint condition is checked after a predefined time interval
B
Correct answer
Explanation
In Oracle, deferred constraints are validated only at transaction commit time, not after each DML operation. This allows intermediate constraint violations during transaction processing. Option A is incorrect because constraints ARE checked - just deferred. Option C describes behavior for initially deferred vs. immediate constraints. Option D is incorrect because there's no time-interval-based checking.
-
False
-
This is hard to determine
-
True
-
None of the choices
C
Correct answer
Explanation
In Oracle SQL, hints are passed to the optimizer using specially formatted comments starting with a plus sign, such as /*+ HINT */. Thus, the statement is true.