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
B
Correct answer
Explanation
AVG and SUM functions only work on numeric data types. They cannot be applied to text, date, or other non-numeric data types. Attempting to use them on strings or dates will result in an error.
-
No. of rows in a table
-
No. of rows with non-null values of the expr
-
No. of distinct non-null values of the expr
-
None of the above
C
Correct answer
Explanation
COUNT(DISTINCT expr) counts the number of unique, non-null values in the specified expression. NULL values are ignored, and duplicate values are counted only once. This is different from regular COUNT(*) which counts all rows including NULLs in some contexts.
-
Group By
-
NVL
-
Order By
-
Having
B
Correct answer
Explanation
Aggregate functions like COUNT, SUM, AVG ignore NULL values by default. The NVL function converts NULL values to a specified value, effectively forcing them to be included in the aggregation. GROUP BY, ORDER BY, and HAVING are clauses, not functions for handling NULL values.
A
Correct answer
Explanation
Standard SQL aggregation rules dictate that any column present in the SELECT clause that is not an argument of an aggregate function must be included in the GROUP BY clause. The statement is true.
-
HAVING
-
WHERE
-
Order By
-
Group by
A
Correct answer
Explanation
HAVING is used to filter groups after aggregation, similar to how WHERE filters individual rows before aggregation. You cannot use WHERE with aggregate functions - HAVING is the correct clause for restricting groups based on aggregate conditions.
B
Correct answer
Explanation
Group functions (aggregate functions) cannot be used in the WHERE clause because WHERE operates on individual rows before grouping. To filter based on aggregate values, you must use HAVING after the GROUP BY clause. This is a fundamental SQL execution order rule.
A
Correct answer
Explanation
An UPDATE statement in SQL can affect zero, one, or multiple rows depending on the criteria specified in the WHERE clause. Thus, updating more than one row with a single statement is fully supported.
-
All rows of the Employee table
-
Rows of the Employee table where the set grade is ‘Y’
-
Delete 1 row
-
Nothing will be deleted
B
Correct answer
Explanation
The DELETE statement with a WHERE clause removes only those rows that satisfy the condition. In this case, only employees whose grade column contains 'Y' will be deleted. All other rows remain untouched. The DELETE without WHERE would remove all rows.
-
CHECK keyword
-
WITH CHECK keyword
-
WITH CHECK OPTION keyword
-
None of the Above
C
Correct answer
Explanation
WITH CHECK OPTION is used with updatable views to prevent modifications that would make rows invisible to the view. It ensures that INSERT or UPDATE operations result in rows that still satisfy the view's defining query, maintaining data integrity and view consistency.
-
INSERT statement
-
UPDATE statement
-
Both of the Above
-
None of the Above
C
Correct answer
Explanation
Explicit defaults can be specified in both INSERT and UPDATE statements. In INSERT, you can explicitly set a column to its default value. In UPDATE, you can reset a column back to its default value using the DEFAULT keyword. This provides flexibility in managing default values during data manipulation.
C
Correct answer
Explanation
In Oracle SQL, the standard group (aggregate) functions are COUNT, AVG, MAX, MIN, SUM, STDDEV, VARIANCE, etc. 'Total' is NOT a valid Oracle group function, making it the correct answer to 'which is NOT a group function'. While some other databases might have a TOTAL function, Oracle does not.
A
Correct answer
Explanation
A subquery is a query nested inside a larger query. The primary purpose of a subquery is to provide values or a temporary result set that the main query uses to complete its execution.
A
Correct answer
Explanation
The LIKE operator in SQL is specifically designed for wildcard searches using pattern matching operators such as percent signs and underscores. It allows you to search for specified patterns in a column.
B
Correct answer
Explanation
In join conditions, specifying table names is NOT mandatory when column names are unambiguous. If a column name exists in only one of the joined tables, you can reference it directly without the table prefix. Table prefixes (or aliases) are only required when column names are ambiguous (exist in multiple tables). The claimed answer 'False' is correct.
-
9
-
11
-
5
-
12
-
None of the above
A
Correct answer
Explanation
To join N tables together, you need at minimum N-1 join conditions. This is because each join reduces the number of unconnected tables by one. Starting with 10 tables, you need 9 joins to connect them all into a single result set. For example: (T1 JOIN T2) JOIN T3 ... JOIN T10 requires 9 joins.