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
CHECK constraints only evaluate to TRUE or FALSE, but they are not evaluated when the value is NULL. NULL values bypass CHECK constraint validation entirely, so they never violate the constraint.
A
Correct answer
Explanation
ROLLUP generates subtotals (super-aggregates) at each hierarchy level in a GROUP BY operation. COUNT, AVG, and SUM are standard aggregate functions that produce single values per group, not hierarchical results.
-
ON DELETE SET NULL
-
ON DELETE CASCADE
-
ON DELETE DELETE
-
ON DELETE RESTRICT
B
Correct answer
Explanation
To answer this question, the user needs to have knowledge of database management systems and the concept of Foreign Keys.
When a Foreign Key references a Primary Key in another table, there is a possibility that the referenced record(s) may be deleted. In such cases, four actions can be taken: SET NULL, CASCADE, DELETE, or RESTRICT.
ON DELETE SET NULL: This option sets the Foreign Key value to NULL when the referenced record(s) are deleted. This may lead to data integrity issues and is not ideal in most cases.
ON DELETE CASCADE: This option deletes all the dependent rows in the child table when the referenced rows in the parent table are deleted. This is usually the preferred option when the child rows are no longer relevant without the parent rows.
ON DELETE DELETE: This syntax does not exist, and hence, it is incorrect.
ON DELETE RESTRICT: This option prevents the deletion of the referenced rows in the parent table when there are dependent rows in the child table. This is useful when the data in the child table is still relevant and associated with the data in the parent table.
Therefore, the correct answer is:
The Answer is: B. ON DELETE CASCADE
-
SUBSTR
-
CON_STR
-
CON_CAT
-
WM_CONCAT
D
Correct answer
Explanation
WM_CONCAT is an Oracle-specific string aggregation function that concatenates values from multiple rows into a single column. SUBSTR extracts substrings, while CON_STR and CON_CAT are not valid SQL functions.
-
Restricts the length of the String
-
Replaces a sequence of characters in a string with another set of characters
-
Modifies the datatype of a column
-
Renames a column
B
Correct answer
Explanation
The TRANSLATE function in SQL replaces a sequence of individual characters in a string with another corresponding set of individual characters, mapping them one-to-one.
B
Correct answer
Explanation
HAVING filters aggregate functions after grouping. WHERE filters rows before aggregation and cannot use aggregate functions. WHEN is used in CASE expressions, and ANY is a comparison operator.
-
IN executes the inner query for each row affected by the outer query and EXISTS executes the inner query only once irrespective of the outer query
-
IN executes the inner query only once irrespective of the outer query and EXISTS executes the inner query only once irrespective of the outer query
-
IN executes the inner query only once irrespective of the outer query and EXISTS executes the outer query for each row affected by the outer query
-
IN executes the inner query for each row affected by the outer query and EXISTS executes the outer query for each row affected by the outer query
C
Correct answer
Explanation
The IN operator evaluates the subquery once to get a list of values, whereas EXISTS evaluates the subquery for each row processed by the outer query to check for the existence of a match.
-
Defined immediately after the table CREATE statement, used to find the Primary Key
-
Defined during the table CREATE statement, used to assign rows to an AMP
-
Defined immediately after the table CREATE statement, used to assign rows to an AMP
-
Defined during the table CREATE statement, used to find the Primary Key
B
Correct answer
Explanation
The Primary Index is defined within the CREATE TABLE statement (not after). Its core purpose is to distribute rows to AMPs via the hashing algorithm. It is not used to find the Primary Key - PK is for uniqueness and relationships.
-
Defined immediately after the table CREATE statement, used to assign rows to an AMP
-
Defined immediately after the table CREATE statement, used to find the Primary Key
-
Defined during the table CREATE statement, used to assign rows to an AMP
-
Defined during the table CREATE statement, used to find the Primary Key
C
Correct answer
Explanation
In Teradata, the Primary Index (PI) is defined during the table CREATE statement. It is used by the hashing algorithm to assign and distribute table rows across Access Module Processors (AMPs).
D
Correct answer
Explanation
The COUNT(*) aggregate function counts the number of rows in a table. If a table has been created but contains no rows, the query returns 0 rather than an error or 'No data Found'.
-
select '''||'TCS'||''' from dual
-
select 'TCS' from dual
-
select '''TCS''' from dual
-
select "TCS" from dual
A
Correct answer
Explanation
In Oracle SQL, a single quote is escaped by doubling it. The expression '''||'TCS'||''' concatenates an escaped single quote, the string 'TCS', and another escaped single quote, resulting in 'TCS'.
-
2009-may-25
-
Error
-
may-2009-25
-
200925may
B
Correct answer
Explanation
The date format string 'yyyymmdd' is incompatible with the input '2009-may-25'. Month abbreviations like 'may' require format codes like 'mon' or 'month', not 'mm'. The mismatch causes Oracle to throw an error rather than attempt conversion.
-
select '''||'TCS ||''' from dual
-
select '''TCS''' from dual
-
select "TCS" from dual
-
select 'TCS' from dual
B
Correct answer
Explanation
To output literal single quotes around TCS, use two consecutive single quotes: '''TCS'''. In Oracle SQL, a single quote within a string is escaped by doubling it. The outer quotes define the string, inner pairs become literal quotes in output.
B
Correct answer
Explanation
Teradata allows a maximum of 32 secondary indexes per table. Secondary indexes provide alternative access paths but consume overhead. The limit exists to balance flexibility with system performance. 64, 128, and 256 are not the correct limits.
B
Correct answer
Explanation
By definition in Teradata and all relational databases, a Primary Key column cannot contain NULL values. The entire purpose of a primary key is to uniquely identify each row, and NULL represents an unknown value that cannot serve as an identifier. Therefore, the statement is false.