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
-
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 DES
C
Correct answer
Explanation
The correct SQL syntax uses ORDER BY (not SORT BY) with DESC for descending order. Options A and B use SORT BY which is incorrect. Option D has incomplete DESC keyword and missing BY. The standard syntax is: SELECT * FROM table ORDER BY column DESC.
-
INSERT VALUES ('Jimmy', 'Jackson') INTO Persons
-
INSERT ('Jimmy', 'Jackson') INTO Persons
-
INSERT INTO Persons VALUES ('Jimmy', 'Jackson')
-
None
C
Correct answer
Explanation
The correct SQL syntax for inserting a record is INSERT INTO table_name VALUES (value1, value2...). Option C shows this correctly. Options A and B have incorrect syntax (INSERT VALUES instead of INSERT INTO VALUES, and INSERT ... INTO instead of INSERT INTO ...).
-
INSERT INTO Persons ('Olsen') INTO LastName
-
INSERT ('Olsen') INTO Persons (LastName)
-
INSERT INTO Persons (LastName) VALUES ('Olsen')
-
None
C
Correct answer
Explanation
When inserting into specific columns, use INSERT INTO table_name (column1, column2...) VALUES (value1, value2...). Option C correctly shows inserting into the LastName column only. Options A and B have incorrect syntax.
-
DELETE ROW FirstName='Peter' FROM Persons
-
DELETE FROM Persons WHERE FirstName = 'Peter'
-
DELETE FirstName='Peter' FROM Persons
-
None
B
Correct answer
Explanation
The standard SQL syntax to delete specific records from a table is 'DELETE FROM table_name WHERE condition'. Thus, 'DELETE FROM Persons WHERE FirstName = 'Peter'' is correct.
-
SELECT COLUMNS() FROM Persons
-
SELECT COUNT(*) FROM Persons
-
SELECT COUNT() FROM Persons
-
SELECT COLUMNS(*) FROM Persons
B
Correct answer
Explanation
To count records in SQL, use the COUNT(*) aggregate function. Option B shows the correct syntax. COUNT() without asterisk (option C) is incomplete, and SELECT COLUMNS() is not valid for counting records.
-
SELECT UNIQUE
-
SELECT DISTINCT
-
SELECT DIFFERENT
-
None
B
Correct answer
Explanation
The DISTINCT keyword in SQL removes duplicate values and returns only unique values. Option B is correct. SELECT UNIQUE and SELECT DIFFERENT are not valid SQL keywords.
A
Correct answer
Explanation
The OR operator returns rows where ANY condition is true, while AND returns rows where ALL conditions are true. This is the standard behavior in SQL and most programming languages.
-
UPDATE Persons SET LastName='Hansen' INTO LastName='Nilsen'
-
MODIFY Persons SET LastName='Nilsen' WHERE LastName='Hansen
-
UPDATE Persons SET LastName='Nilsen' WHERE LastName='Hansen'
-
MODIFY Persons SET LastName='Hansen' INTO LastName='Nilsen
C
Correct answer
Explanation
The standard SQL syntax to modify data uses the UPDATE statement combined with SET to assign the new value and a WHERE clause to specify which rows to change.
-
Having a single SQL query with FACT A, FACT B and Conf D.
-
Have a individual query between FACT A & Conf D, and a individual query between FACT B & Conf D.
-
Have three individual queries, one for each table.
-
A and B
-
All of the above
B
Correct answer
Explanation
With conformed dimensions, the best practice is to query each fact table separately against the shared dimension (individual queries). A single query joining both facts directly would create a snowflake pattern that can cause performance issues and incorrect results due to fact table explosion (cartesian product of fact rows).
B
Correct answer
Explanation
AUD$ is the audit trail table in Oracle that can be modified, typically for maintenance purposes like truncating old audit records. Other SYS tables like COL$ and ROW$ are data dictionary tables that should never be directly modified.
-
Names are case sensitive.
-
Names must not be oracle server reserve word.
-
Table names and column names need not be start with a letter.
-
We cannot use a column alias in a WHERE clause
B,D
Correct answer
Explanation
In Oracle SQL, table/column names cannot be reserved words (like SELECT, FROM, etc.) without quoting. Column aliases (defined in SELECT clause) cannot be used in WHERE clause because WHERE is processed before SELECT. Names are case-insensitive and must start with a letter.
-
Select
-
Insert
-
Update
-
Create
-
Delete
-
Alter
A,B,C,E
Correct answer
Explanation
DML (Data Manipulation Language) commands operate on existing data within database objects. SELECT retrieves data, INSERT adds new rows, UPDATE modifies existing data, and DELETE removes rows. CREATE and ALTER are DDL (Data Definition Language) commands that define or modify database structures, not manipulate data.
-
The column contain wide range of values.
-
The column contain large number of Null values.
-
The table is large.
-
Columns which are not frequently used.
A,B,C
Correct answer
Explanation
Indexes are beneficial when columns contain wide range of values (high cardinality), when tables are large (performance impact is significant), and when columns contain many NULL values (indexes can efficiently skip NULLs). Columns that are infrequently used don't benefit from indexing as the query performance gain wouldn't justify the storage and maintenance overhead.
-
When an entire index is scanned to locate rows we call it as index scan
-
When only part of the index is scanned to locate rows we call it as index scan
-
When all the rows are scanned we call it as index scan
-
None of the above
A
Correct answer
Explanation
An index scan occurs when DB2 accesses and searches the index structure itself to locate the requested rows, rather than scanning the entire tablespace.
-
Complex Key
-
Secondary Key
-
Composite Key
-
Foreign Key
C
Correct answer
Explanation
A composite key is a key that consists of two or more columns used together to uniquely identify a row in a table. Unlike a simple key that uses a single column, composite keys combine multiple columns to ensure uniqueness when no single column can uniquely identify records.