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
A
Correct answer
Explanation
Locksize ANY is the default and lets DB2 choose between page, row, or table locks based on access patterns. While valid, optimal performance often requires explicit locksize selection based on workload characteristics.
A
Correct answer
Explanation
SQLCABC (SQL Communication Area Byte Count) contains the length of the SQLCA structure. It exists to verify SQLCA size compatibility between different program and DB2 versions, making the statement essentially correct.
-
condition names
-
RENAMES clause
-
All the above
-
None
A
Correct answer
Explanation
In COBOL, level 88 is used exclusively for condition names - boolean flags that can be set true/false based on specific data conditions. Level 88 entries define conditional status flags associated with their parent elementary item, used for program logic flow control, not for RENAMES or regular data storage.
-
binary search & the table must be sorted
-
serial search
-
binary search
-
All the above
B
Correct answer
Explanation
The SEARCH verb in COBOL performs a serial (sequential) search by default, examining table elements one-by-one until a match is found. The table need not be sorted. For binary search on sorted tables, COBOL provides SEARCH ALL, not SEARCH. The question specifically asks about SEARCH command without ALL.
B
Correct answer
Explanation
Having 30 extents is NOT necessarily bad. In locally managed tablespaces with uniform extent sizes, multiple extents are normal and expected. Extent count alone doesn't indicate performance issues.
-
Check
-
Unique
-
Not Null
-
Primary Key
-
Foreign Key
D
Correct answer
Explanation
A PRIMARY KEY constraint uniquely identifies each row AND implicitly enforces NOT NULL, satisfying both rules. UNIQUE allows nulls, CHECK doesn't enforce uniqueness, NOT NULL doesn't enforce uniqueness, and FOREIGN KEY references other tables.
-
Check
-
Unique
-
Not Null
-
Primary Key
-
Foreign Key
D
Correct answer
Explanation
A Primary Key constraint enforces both uniqueness (no duplicate values) and the NOT NULL constraint (no null values). This makes it the only single constraint type that guarantees both business rules are satisfied simultaneously for a table column.
-
SELECT text FROM user_source WHERE name = 'SALARY_CALC';
-
SELECT * FROM user_source WHERE name='SALARY_CALC';
-
SELECT * FROM user_objects WHERE object_name='SALARY_CALC';
-
SELECT * FROM user_procedures WHERE object_name='SALARY_CALC';
-
SELECT text FROM user_source WHERE name='SALARY_CALC' and owner='JOHN'
A
Correct answer
Explanation
To view the source code text of a stored procedure in Oracle, you query the 'text' column of the 'user_source' data dictionary view where the 'name' matches the procedure name in uppercase.
-
It performs a merge join of the row from T2 only if it does'nt exist in the T1 table.
-
It creates a natural join of table T1 and T2 for all columns that have the same name.
-
It creates a Cartesian prodcut of table T1 and table T2 for all columns that have the same name.
-
For each row from T2, it updates the row if it exists witin table T1, otherwise it inserts the row into T1.
D
Correct answer
Explanation
The MERGE statement (also called UPSERT) combines UPDATE and INSERT operations. For each row from the source table T2, it evaluates the join predicate against T1. If a matching row exists in T1, it updates that row; if no match exists, it inserts the new row into T1.
-
Check
-
Unique
-
Not Null
-
Primary Key
-
Foreign Key
D
Correct answer
Explanation
A Primary Key constraint enforces both uniqueness and non-null requirements simultaneously. It uniquely identifies each row (no duplicates) and implicitly prevents NULL values. A Unique constraint allows one NULL value, Not Null doesn't prevent duplicates, Check validates expressions, and Foreign Key references other tables. Only Primary Key combines both rules.
-
SELECT text FROM user_source WHERE name = 'SALARY_CALC';
-
SELECT * FROM user_source WHERE name='SALARY_CALC';
-
SELECT * FROM user_objects WHERE object_name='SALARY_CALC';
-
SELECT * FROM user_procedures WHERE object_name='SALARY_CALC';
-
SELECT text FROM user_source WHERE name='SALARY_CALC' and owner='JOHN'
A
Correct answer
Explanation
The USER_SOURCE view contains the source code for stored objects owned by the current user. The TEXT column specifically holds the code text. Option A correctly filters by name and selects the text column. Option B retrieves all columns but still works. Option C queries USER_OBJECTS which only contains metadata about objects, not their source code. Option D queries USER_PROCEDURES which is also a metadata view. Option E incorrectly adds an OWNER filter to USER_SOURCE, but this view only shows objects owned by the current user.
-
It performs a merge join of the row from T2 only if it does'nt exist in the T1 table.
-
It creates a natural join of table T1 and T2 for all columns that have the same name.
-
It creates a Cartesian prodcut of table T1 and table T2 for all columns that have the same name.
-
For each row from T2, it updates the row if it exists witin table T1, otherwise it inserts the row into T1.
D
Correct answer
Explanation
The MERGE statement combines INSERT and UPDATE operations in a single statement. For each row in the source table (T2), it checks if a matching row exists in the target table (T1) based on the join condition. If a match exists, it updates the existing row in T1. If no match exists, it inserts a new row into T1. This is an efficient way to synchronize data between tables. Options A, B, and C describe other types of operations (merge join, natural join, Cartesian product) that are not what MERGE does.
-
A lock is the mechanism that controls access to rows and coloumns
-
A lock is the mechanism that controls access to table views
-
A lock is the mechanism that controls access to data pages and table spaces.
-
None of the Above
C
Correct answer
Explanation
DB2 locks control access to physical and logical data resources like table spaces, tables, and data pages to ensure concurrency. They do not lock individual columns (making the first option incorrect) or views directly (making the second option incorrect), making the third option the most accurate.
-
SELECT COUNT(*) IN Sales
-
SELECT NUM() FROM Sales
-
SELECT COUNTER(*) FROM Sales
-
SELECT COUNT(*) FROM Sales
D
Correct answer
Explanation
COUNT(*) is the standard SQL aggregate function that returns the total number of rows in a table, including NULL values. The correct syntax requires FROM, not IN, to specify the table source. Option D uses the proper SQL syntax while other options use non-existent functions like NUM(), COUNTER(), or incorrect prepositions.
-
INSERT Projects ('Content Development', 'Website content development project')
-
INSERT INTO Projects (ProjectName, ProjectDescription) VALUES ('Content Development', 'Website content development project')
-
INSERT Projects VALUES ('Content Development', 'Website content development project')
-
SAVE INTO Projects (ProjectName, ProjectDescription) VALUES ('Content Development', 'Website content development project')
B
Correct answer
Explanation
INSERT INTO is the standard SQL statement with the syntax requiring column names in parentheses followed by VALUES and the data to insert. Option B correctly specifies both column names (ProjectName, ProjectDescription) and their corresponding values. Options A and C miss the required INTO keyword and column specification, while D uses SAVE which is not a SQL keyword.