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
-
Error: Syntax error
-
INFINITY
-
NULL
-
0
-
Error: divisor is equal to zero
E
Correct answer
Explanation
Attempting to divide by zero in Oracle SQL raises a runtime exception with the message 'ORA-01476: divisor is equal to zero' rather than returning NULL or Infinity.
-
0
-
1
-
NULL
-
Error: divisor is equal to zero
-
Error: Not a GROUP BY clause
A
Correct answer
Explanation
In SQL, 0 divided by 1 equals 0. The GROUP BY clause is valid here because DUAL has a DUMMY column. Oracle performs integer arithmetic, so 0/1 evaluates to 0, not a decimal.
-
Error: Not a GROUP BY Clause
-
X,0
-
X,1
-
Two rows of value (X,0) & (X,1)
-
No rows returned
C
Correct answer
Explanation
DUAL contains exactly one row where DUMMY='X'. COUNT(1) counts the number of rows, which is 1. The GROUP BY clause is properly formed.
-
5
-
25
-
125
-
1
-
Error: Syntax error
A
Correct answer
Explanation
MAX(5), MIN(5), and AVG(5) all return 5 because the aggregate functions operate on a single value. So 5*5/5 = 5. The GROUP BY is valid.
-
Error: Invalid Number
-
Error: Invalid Character
-
0
-
1
-
Error: divisor is equal to zero
A
Correct answer
Explanation
AVG() requires numeric input, but DUMMY contains 'X' (a string value in DUAL). Oracle cannot convert 'X' to a number, raising ORA-01722: invalid number.
-
Two rows of value X and X
-
Error: SQL command not properly ended
-
Error: Not a proper GROUP BY clause
-
X
-
NULL
A
Correct answer
Explanation
MIN(DUMMY) returns 'X' and MAX(DUMMY) returns 'X'. UNION ALL combines both results, producing two rows. DUAL has only one row with DUMMY='X'.
-
X
-
Two rows of value X and X
-
Error: Not a proper ORDER BY clause
-
Error: SQL command not properly ended
-
1
D
Correct answer
Explanation
ORDER BY cannot appear in the first SELECT of a UNION ALL - it must be at the end of the entire statement. This causes 'SQL command not properly ended'.
-
Error: Missing expression
-
connect
-
It will show connection string name
-
NULL
A
Correct answer
Explanation
CONNECT is an Oracle reserved keyword (used for hierarchical queries: CONNECT BY). Using it as a column name without quotes causes 'missing expression' error.
-
It will show one row but no column, no value, not even a NULL value.
-
1
-
0
-
NULL
-
One row with one column containing the ROWID of DUAL's single row (an 18-character rowid string, e.g. AAAADeAABAAAAgiAAA).
E
Correct answer
Explanation
ROWID is a pseudo-column that exists for every row in Oracle tables. Querying it from DUAL returns the actual 18-character ROWID string (e.g., AAAADeAABAAAAgiAAA) of DUAL's single row.
-
It will show one row but no no column,no value-,not even NULL value
-
NULL
-
0
-
1
D
Correct answer
Explanation
ROWNUM is a pseudo-column that assigns a number to each row returned. DUAL has one row, so ROWNUM=1 for that row. The query returns 1.
-
1
-
Values 1 to 50
-
Values 0 to 50
-
0
B
Correct answer
Explanation
CONNECT BY with LEVEL generates hierarchical rows. LEVEL starts at 1, increments by 1. The condition LEVEL BETWEEN 0 AND 50 is true for LEVEL=1 through 50. Output is values 1 through 50.
-
1
-
No rows returned
-
Values 1 to 50
-
Values 0 & 1
B
Correct answer
Explanation
Both hierarchical queries generate the same sequence of numbers from 1 to 50. Subtracting the second result set from the first using MINUS results in an empty set, yielding no rows returned.
C
Correct answer
Explanation
CONNECT BY generates rows starting at LEVEL=1. The filtering condition LEVEL BETWEEN 3 AND 50 is applied AFTER row generation. But the condition fails for LEVEL=1 and LEVEL=2, stopping generation. Only LEVEL=1 satisfies 1 BETWEEN 3 AND 50 = FALSE, so no rows generated beyond first. Oracle returns just the initial row with LEVEL=1.
-
Every entity must have a primary key
-
It is not necessary to define primary key for an Entity
-
@Primary annotation is used for denoting a simple primary key
-
All the above
A
Correct answer
Explanation
In JPA and entity frameworks, every entity MUST have a primary key to uniquely identify each instance. This is a fundamental requirement for entity mapping and database operations. Option B is incorrect because the primary key IS required. Option C is incorrect because @Primary is not a standard JPA annotation for simple primary keys (typically @Id is used). Option D is incorrect since not all statements are valid.