Computer Knowledge
Database and SQL
4,213 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
Group functions (aggregate functions like COUNT, SUM, AVG, MAX, MIN) cannot be used in WHERE clause. WHERE filters individual rows before grouping. Group functions must be used in HAVING clause or SELECT list, after grouping has occurred. This is a fundamental SQL rule.
-
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 specifically removes only those rows that satisfy the condition. This statement will delete all employee records where the grade column equals 'Y', leaving other rows untouched.
-
CHECK keyword
-
WITH CHECK keyword
-
WITH CHECK OPTION keyword
-
None of the Above
C
Correct answer
Explanation
WITH CHECK OPTION is a clause used with updatable views that prevents INSERT or UPDATE operations on rows that would not be visible through the view. It ensures that DML operations only affect rows that satisfy the subquery defining the view.
-
INSERT statement
-
UPDATE statement
-
Both of the Above
-
None of the Above
C
Correct answer
Explanation
The DEFAULT keyword can be explicitly used in both INSERT and UPDATE statements to assign a column's default value. In INSERT, you can specify VALUES (DEFAULT), and in UPDATE, you can use SET column = DEFAULT.
-
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) returns the number of unique, non-null values for the specified expression. It eliminates both NULL values and duplicate values from the count, giving the count of distinct values present.
-
Group By
-
NVL
-
Order By
-
Having
B
Correct answer
Explanation
Aggregate functions like SUM and AVG ignore NULL values by default. The NVL function converts NULL values to a specified non-null value (like 0), allowing those converted values to be included in aggregate calculations.
-
HAVING
-
WHERE
-
Order By
-
Group by
A
Correct answer
Explanation
The HAVING clause filters grouped results after the GROUP BY operation, while WHERE filters individual rows before grouping. HAVING can use aggregate functions like COUNT, SUM, or AVG, which WHERE cannot.
-
Distinct
-
Projection
-
Where
-
All of the above
C
Correct answer
Explanation
The WHERE clause filters rows from a table before any grouping or aggregation occurs. It applies row-level filtering based on specified conditions.
-
Projection
-
Selection
-
Join
-
All of the above
D
Correct answer
Explanation
The SELECT statement performs projection (selecting specific columns), selection (filtering rows with WHERE), and joining (combining data from multiple tables). These are the three fundamental capabilities of SQL queries.
-
Select all columns from EMP;
-
Select distinct columns from EMP;
-
Select * from EMP;
-
All of the above
C
Correct answer
Explanation
In SQL, the asterisk (*) wildcard character is used in the SELECT clause to specify that all columns from the target table should be returned. Options using "all columns" or "distinct columns" are syntactically invalid in standard SQL.
B
Correct answer
Explanation
The statement fails because string literals in SQL must be enclosed in single quotes, not double quotes. The correct syntax would be WHERE ename = 'Scott'. Double quotes are typically used for identifiers like column or table names.
-
Structured Query Language
-
Standard Query Language
-
System Query Language
-
Simple Query Language
A
Correct answer
Explanation
SQL stands for Structured Query Language. It's the standard language for relational database management systems, used for querying, manipulating, and defining data structures in databases.
-
Duplicate
-
Distinct
-
Remove
-
Delete
B
Correct answer
Explanation
The DISTINCT keyword is used in a SELECT statement to eliminate duplicate rows from the result set. For example, SELECT DISTINCT department FROM employees returns each department only once, regardless of how many employees belong to it.