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
-
Structured Query Language
-
Strong Question Language
-
Structured Question Language
-
None
A
Correct answer
Explanation
SQL stands for Structured Query Language, the standard language for relational database management systems. It's used for querying, updating, and managing data. Options B and C incorrectly substitute 'Question' for 'Query'.
-
SELECT Persons.FirstName
-
SELECT FirstName FROM Persons
-
EXTRACT FirstName FROM Persons
-
None
B
Correct answer
Explanation
To select a specific column from a table, use SELECT column_name FROM table_name. This retrieves only the specified column for all rows. Option A uses incorrect dot notation (Persons.FirstName), C uses non-existent EXTRACT keyword, and the syntax for column selection is simply SELECT followed by the column name.
-
SELECT (A); WHEN (A=0) PUT LIST(‘A = 0‘); WHEN (A=5) PUT LIST (‘A = 5‘); OTHERWISE PUT LIST (‘A IS NOT 0 NOR 5’); END;
-
SELECT (A); WHEN (0) PUT LIST(‘A = 0‘); WHEN (5) PUT LIST (‘A = 5‘); OTHERWISE PUT LIST (‘A IS NOT 0 NOR 5’); END;
-
SELECT; WHEN (A=0) PUT LIST(‘A = 0‘); WHEN (5) PUT LIST (‘A = 5‘); OTHERWISE PUT LIST (‘A IS NOT 0 NOR 5’); END;
-
All of the above
B
Correct answer
Explanation
Option B is correct because PL/I SELECT statements allow WHEN clauses with simple expressions that evaluate against the selector value. Option A is wrong because WHEN (A=0) is a comparison, not the value itself. Option C is wrong because it omits the selector (A) after SELECT. Option D is wrong since only B is correct.
-
For Renames Clause
-
For Condition Names
-
Elementary level item. Cannot be subdivisions of other items (cannot be qualified), nor can they be subdivided themselves.
-
All of the above
A
Correct answer
Explanation
In COBOL, level number 66 is specifically reserved for the RENAMES clause, which allows regrouping or renaming previously defined elementary items. Level 88 is used for condition names, and level 77 is used for independent elementary items.
B
Correct answer
Explanation
Primary Key constraints cannot contain NULL values by definition. Each row must have a unique, non-NULL identifier. This is a fundamental property of primary keys in relational databases.
B
Correct answer
Explanation
A composite key combines multiple columns to create a unique identifier. The entire combination cannot be NULL, though individual components might allow NULLs in some systems. For the key to function as an identifier, at least one component must be non-NULL.
-
SORT BY
-
SORT
-
ORDER
-
ORDER BY
D
Correct answer
Explanation
ORDER BY is the SQL clause used to sort query results in ascending (ASC) or descending (DESC) order based on one or more columns. Options like SORT BY or just ORDER/SORT are not valid SQL syntax.
-
MODIFY Persons SET LastName='Nilsen' WHERE LastName='Hansen'
-
MODIFY Persons SET LastName='Hansen' INTO LastName='Nilsen
-
UPDATE Persons SET LastName='Hansen' INTO LastName='Nilsen'
-
UPDATE Persons SET LastName='Nilsen' WHERE LastName='Hansen'
D
Correct answer
Explanation
The UPDATE statement modifies existing data in a table. The correct syntax is UPDATE table_name SET column=new_value WHERE condition. Option D correctly changes 'Hansen' to 'Nilsen' for all matching rows. MODIFY is not a valid SQL keyword.
-
SELECT COUNT(*) FROM Persons
-
SELECT COLUMNS(*) FROM Persons
-
SELECT COLUMNS() FROM Persons
-
SELECT COUNT() FROM Persons
A
Correct answer
Explanation
COUNT() is an aggregate function that returns the total number of rows in a table. The asterisk () indicates count all rows regardless of NULL values. Options B, C, and D use incorrect syntax (COLUMNS is not a valid SQL keyword, and COUNT() requires the * parameter).
-
SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter'
-
SELECT * FROM Persons WHERE FirstName<>'Peter'
-
SELECT [all] FROM Persons WHERE FirstName='Peter'
-
SELECT * FROM Persons WHERE FirstName='Peter'
D
Correct answer
Explanation
SELECT * retrieves all columns, and WHERE FirstName='Peter' filters for exact matches. The = operator is for exact matching (not LIKE, which is for patterns). Options A and C incorrectly use [all] instead of *, and option B uses <> (not equal) which would exclude 'Peter'.
-
SELECT * FROM Persons WHERE FirstName LIKE '%a'
-
SELECT * FROM Persons WHERE FirstName='%a%'
-
SELECT * FROM Persons WHERE FirstName='a'
-
SELECT * FROM Persons WHERE FirstName LIKE 'a%'
D
Correct answer
Explanation
The LIKE operator with 'a%' matches any string starting with 'a' followed by any characters. The % is a wildcard representing zero or more characters. Option A's '%a' matches ending with 'a', B's syntax is invalid, C matches only exact 'a', and D's 'a%' correctly matches starting with 'a'.
-
SELECT * FROM Persons SORT BY 'FirstName' DESC
-
SELECT * FROM Persons SORT 'FirstName' DESC
-
SELECT * FROM Persons ORDER BY FirstName DESC
-
SELECT * FROM Persons ORDER FirstName DESC
C
Correct answer
Explanation
ORDER BY is the correct clause for sorting (not SORT BY), DESC specifies descending order, and column names don't require quotes. Option C has the correct syntax. Options A, B use invalid SORT keywords, and D is missing the BY.
C
Correct answer
Explanation
SELECT is the fundamental SQL statement for retrieving data from databases. It specifies which columns to fetch and from which table. Options A (OPEN), B (EXTRACT - not a data retrieval verb in SQL), and D (GET) are not valid SQL statements for querying data.
-
UPDATE
-
MODIFY
-
SAVE
-
SAVE AS
A
Correct answer
Explanation
The UPDATE statement is the standard SQL command for modifying existing data in database tables. MODIFY, SAVE, and SAVE AS are not valid SQL DML statements - they are not part of the SQL language specification.