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
-
Select all columns from EMP;
-
Select distinct columns from EMP;
-
Select * from EMP;
-
All of the above
C
Correct answer
Explanation
This is an exact duplicate of question 139506. SELECT * from EMP; is correct syntax where * selects all columns from the EMP table.
B
Correct answer
Explanation
In standard SQL, character literals must be enclosed in single quotes ('Scott'). Double quotes are reserved for database identifiers like table or column names. Using double quotes for a string literal causes a compilation or execution error, making the statement false.
-
Structured Query Language
-
Standard Query Language
-
System Query Language
-
Simple Query Language
A
Correct answer
Explanation
SQL stands for Structured Query Language, which is the standard programming language used to manage and manipulate relational databases. The other options, such as Standard, System, or Simple Query Language, are incorrect expansions of the acronym and do not represent the official name.
-
Duplicate
-
Distinct
-
Remove
-
Delete
B
Correct answer
Explanation
In SQL, the DISTINCT keyword is used in SELECT statements to remove duplicate rows from the result set, returning only unique values. While options like 'Duplicate', 'Remove', and 'Delete' might seem conceptually related, they are not valid SQL keywords for this purpose. DISTINCT is the standard SQL operator specifically designed for eliminating duplicate values.
-
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 broadly classified based on the number of rows they return to the outer query. Single-row subqueries return only one row, whereas multiple-row subqueries return one or more rows. The other options incorrectly include non-existent concepts like double-row subqueries.
-
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 and one column. This type of subquery is typically used with single-row comparison operators like =, >, <, >=, or <=. If a single-row subquery returns more than one row, it will cause an error, and if it returns no rows, the result is null.
-
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 groups by Rollnum, returning the minimum marks for each group, which results in multiple rows. Because the outer query uses the single-value comparison operator =, it fails with a 'single-row subquery returns more than one row' error. Other options are incorrect as the query cannot execute successfully.
C
Correct answer
Explanation
The ALL operator in SQL compares a value to every value returned by a subquery, evaluating to true only if the comparison is true for all values. For example, 'salary > ALL (subquery)' returns true only if the salary is greater than every single value returned by the subquery. IN checks membership, ANY returns true if at least one comparison succeeds, and OF is not a valid SQL 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 (adding new rows), UPDATE (modifying existing rows), and DELETE (removing existing rows). Since all three operations are fundamental DML operations, option D is correct as it encompasses all the individual DML actions listed in the other options.
-
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 values is 'INSERT INTO tablename VALUES (...)' which directly inserts values into a table. Options A and B have incorrect syntax ('Insert to' and 'insert into table' are not valid). Option C correctly shows 'Insert into table tablename values' though it would typically be 'INSERT INTO tablename VALUES' without the word 'table' - but among the given choices, C is the closest to correct syntax.
-
Delete
-
Select
-
Update
-
Insert
B
Correct answer
Explanation
FastExport is a read-only utility designed specifically for high-volume data extraction from Teradata. Only SELECT queries are permitted within FastExport tasks. INSERT, UPDATE, and DELETE are data modification commands that are not supported.
-
WHERE prod_id LIKE '%D123%' ESCAPE ''
-
WHERE prod_id LIKE '%_D123%' ESCAPE ''
-
WHERE prod_id LIKE '%D123%' ESCAPE '%'
-
WHERE prod_id LIKE '%_D123%' ESCAPE '_'
B
Correct answer
Explanation
The LIKE operator with '%_D123%' would match any string containing '_D123', but underscore is a wildcard matching any single character. To search for a literal underscore, you need to escape it using the ESCAPE clause. Option B correctly uses backslash as the escape character (ESCAPE '\') and prefixes the underscore with backslash (_) to treat it as a literal character. Options A and C are incorrect because they don't properly escape the underscore. Option D incorrectly uses '_' as the escape character instead of '\'.
-
They accept only a single argument.
-
.They can be nested only to two levels.
-
Arguments can only be column values or constants.
-
They always return a single result row for every row of a queried table.
-
They can return a data type value different from the one that is referenced.
D,E
Correct answer
Explanation
Single-row functions operate on each row independently and return exactly one result per input row (option D). They can return data types different from their input arguments - for example, TO_CHAR converts numbers to strings, and NVL can return different types based on its first argument (option E). Options A, B, and C are false: single-row functions accept multiple arguments (like SUBSTR), can be nested deeply beyond two levels, and accept expressions, not just column values or constants.
-
Both USING and ON clauses can be used for equijoins and nonequijoins.
-
A maximum of one pair of columns can be joined between two tables using the ON clause.
-
The ON clause can be used to join tables on columns that have different names but compatible data
-
The WHERE clause can be used to apply additional conditions in SELECT statements containing the
C,D
Correct answer
Explanation
The ON clause allows joining tables on columns with different names as long as data types are compatible (option C) - this is its primary advantage over USING. The WHERE clause can always add additional filter conditions after the JOIN clause (option D). Option A is false: USING only works for equijoins (columns with same name), while ON works for any condition. Option B is false: the ON clause can join on multiple column pairs using AND conditions.
-
It ignores NULL values.
-
Reversing the order of the intersected tables alters the result.
-
The names of columns in all SELECT statements must be identical.
-
The number of columns and data types must be identical for all SELECT statements in the query.
D
Correct answer
Explanation
INTERSECT requires that all SELECT statements in the query have the same number of columns and matching data types (option D) - this is a fundamental requirement for set operations. Option A is false: INTERSECT treats NULL values like any other value and includes them in results. Option B is false: INTERSECT is commutative - order doesn't affect the result set. Option C is false: column names don't need to match; only position and data type must align.