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
-
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.
A
Correct answer
Explanation
SQL requires that any column in the SELECT list that is not part of an aggregate function must be included in the GROUP BY clause. This ensures each row in the result represents a distinct group summary.
-
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.
-
Single-row subquery, Double-row subquery
-
Double-row subquery, Multiple-row subquery
-
Multiple-row subquery
-
Single-row subquery and Multiple subquery
D
Correct answer
Explanation
Subqueries are categorized into two main types based on the number of rows they return: single-row subqueries (which return exactly one row and use single-row operators like =, >, <) and multiple-row subqueries (which return multiple rows and require operators like IN, ANY, or ALL).
-
Only one row
-
Two rows
-
Zero rows
-
There is no such subquery
A
Correct answer
Explanation
A single-row subquery is designed to return exactly one row from the inner query. This type of subquery can be used with single-row comparison operators like =, >, <, etc. Options B and C are incorrect because they describe multi-row or no-row scenarios, while D is false as single-row subqueries are a valid SQL construct.
-
It gives the name and marks of all the students.
-
It does not return anything.
-
It shows an error saying” INVALID SYNTAX ERROR”
-
It shows an error saying” Single-row subquery returns more than one row
D
Correct answer
Explanation
The subquery uses GROUPBY (should be GROUP BY) on Rollnum, which returns one minimum mark value per unique Rollnum - potentially multiple rows. The outer query uses the single-row comparison operator = with stud_marks, expecting exactly one value. When the subquery returns multiple rows (one per Rollnum group), this creates a mismatch and triggers the 'single-row subquery returns more than one row' error.
C
Correct answer
Explanation
ALL is a SQL operator that compares a value to EVERY value returned by a subquery. For example, 'salary > ALL (SELECT salary FROM employees)' means the salary must be greater than every salary in the subquery results. IN checks membership in a set, ANY checks if the condition is true for at least one value, and OF is not a comparison operator.
-
Add new rows to a table
-
Modify existing rows of a table
-
Remove existing rows from a table
-
All of the above
D
Correct answer
Explanation
DML (Data Manipulation Language) statements include INSERT (add new rows), UPDATE (modify existing rows), and DELETE (remove existing rows). Since all three operations are DML statements, 'All of the above' is correct. DML commands specifically manipulate data stored in database tables.
-
Insert to table tablename (….);
-
Insert into table tablename (….);
-
Insert into table tablename values (…..);
-
Any one of the above
C
Correct answer
Explanation
The correct SQL syntax for inserting a row is 'INSERT INTO tablename VALUES (...)' or 'INSERT INTO tablename (columns) VALUES (...)'. Option C shows the basic form with VALUES clause. Options A and B use incorrect syntax ('Insert to' and 'Insert into table' instead of 'INSERT INTO'). D is incorrect because not all forms shown are valid.