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
-
check (salary>(select salary from emp where uid=10))
-
check (salary >(select salary from emp where rowid=10 ))
-
check (salary >2568)
-
check (salary >select salary from emp where dno=10)
C
Correct answer
Explanation
CHECK constraints cannot contain subqueries or references to other rows - they must evaluate to a boolean condition using only the current row's values. Option C uses a literal value (2568), making it valid. Options A, B, and D use subqueries, which are not allowed.
-
deletes data from table but keeps table structure
-
deletes data as well table structure
-
drops table
-
none of the above
A
Correct answer
Explanation
TRUNCATE removes all rows from a table but preserves the table structure and associated objects (indexes, constraints). Unlike DELETE, TRUNCATE is DDL (cannot be rolled back) and is faster for removing all data.
-
1 11 111 2 3 4
-
1 2 3 4 11 111
-
111 11 4 3 2 1
-
ERROR due to data type mismatch
A
Correct answer
Explanation
VARCHAR columns store character data, so ORDER BY uses lexicographic (dictionary) sorting, not numeric. String '11' comes before '2' because '1' < '2'. The sorted order is: 1, 11, 111, 2, 3, 4.
-
Union all will remove the duplicate rows from the result set while Union does'nt
-
Union will remove the duplicate rows from the result set while Union all does'nt
-
Both Union and Union all will remove duplicate rows from result set
-
All of the above
B
Correct answer
Explanation
The UNION operator combines the results of two queries and removes duplicate rows, whereas UNION ALL combines the results and includes all duplicates, making UNION slower but cleaner.
A
Correct answer
Explanation
Each AMP is assigned a specific portion of every table's rows through hashing. This distributed architecture allows parallel processing across all AMPs.
-
Unique
-
Non Unique
-
Null
-
Not Null
-
All of the above
A,D
Correct answer
Explanation
A Primary Key constraint enforces two database integrity rules: every value in the primary key column(s) must be unique, and no value in the primary key column(s) can be null.
-
5392845.324
-
871039453.1
-
97234512.123
-
1234567.12
B
Correct answer
Explanation
A column defined as NUMBER(10,2) can hold up to 10 significant digits, with 2 of those to the right of the decimal point (leaving 8 digits for the integer part). '871039453.1' has 9 integer digits, causing an overflow error.
-
having clause
-
where clause
-
order by clause
-
group by clause
C
Correct answer
Explanation
A subquery cannot contain an ORDER BY clause because subqueries are used to define a set of data, and sorting is only meaningful for the final presentation of the main query's output.
C
Correct answer
Explanation
The LENGTH function in Oracle/SQL counts the number of characters in a string expression, including special characters and signs. For LENGTH(-1), the function treats '-1' as a two-character string (minus sign and digit 1), not as a numeric value. The output is 2, not 1 (the digit count) or 0. This demonstrates that LENGTH operates on string representation, not mathematical values.
A
Correct answer
Explanation
COUNT(column_name) explicitly ignores NULL values in the specified column. With 14 total rows and one NULL in MGR, COUNT(mgr) returns 13 (not 14). This differs from COUNT(*) which counts all rows regardless of NULL values. Option A correctly states the result is less than 14, though the precise value is 13. The question tests understanding of aggregate function behavior with NULL values.
-
Not NULL
-
Primary key
-
Foreign key
-
Composite primary keys
D
Correct answer
Explanation
Composite primary keys (primary keys consisting of more than one column) cannot be declared at the column level; they must be declared using table constraint syntax.
-
Primary key access
-
Access via unique index
-
Table access by ROWID
-
Full table scan
C
Correct answer
Explanation
ROWID access is fastest because ROWID contains the physical disk address of the row, enabling direct retrieval without traversing indexes. Primary key and unique index access require index traversal to find the ROWID first, then row access. Full table scan reads all blocks, making it slowest for single-row retrieval. ROWID is essentially a direct pointer to the row's location on disk.
B
Correct answer
Explanation
To join N tables without Cartesian products, you need N-1 join conditions. For 4 tables, you need 3 conditions. Each condition links two tables together. With 3 conditions for 4 tables, you create a chain: T1-T2, T2-T3, T3-T4. Fewer than 3 conditions would leave some tables disconnected, creating Cartesian products between disconnected sets. The minimum is n-1 conditions to connect n tables.
D
Correct answer
Explanation
In DB2 SQL PL, if a local variable is declared without an explicit default value using the DEFAULT clause, its initial value is automatically set to NULL.