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
-
One
-
More than One
-
None
-
Stored Procedure Does not support Output Parameter
B
Correct answer
Explanation
SQL Server stored procedures can have multiple OUTPUT parameters. You can define as many output parameters as needed (within practical limits), making B the correct answer.
-
Stored Procedure
-
Function
-
Table
-
View
C
Correct answer
Explanation
Triggers are primarily associated with tables and execute in response to INSERT, UPDATE, or DELETE operations on that table. While INSTEAD OF triggers can also be created on views, tables are the fundamental object for which triggers are defined.
-
Open
-
Get
-
Extract
-
None of the Above
-
SELECT * FROM Persons WHERE FirstName='%a%'
-
SELECT * FROM Persons WHERE FirstName='a'
-
SELECT * FROM Persons WHERE FirstName LIKE '%a'
-
SELECT * FROM Persons WHERE FirstName LIKE 'a%'
D
Correct answer
Explanation
The SQL LIKE operator with 'a%' matches any string starting with 'a'. The % wildcard matches zero or more characters. Option A ('%a%') would match any string containing 'a' anywhere. Option B is exact equality. Option C ('%a') matches strings ending with 'a'.
-
SELECT * FROM Persons WHERE FirstName<>'Peter' AND LastName<>'Jackson'
-
SELECT FirstName='Peter', LastName='Jackson' FROM Persons
-
SELECT * FROM Persons WHERE FirstName='Peter' AND LastName='Jackson'
-
None
C
Correct answer
Explanation
The correct SQL uses WHERE with AND operator to combine two conditions. Option A uses <> which means 'not equal'. Option B has incorrect syntax - column names appear before FROM. The correct syntax is SELECT * FROM table WHERE column1='value1' AND column2='value2'.
-
SELECT * FROM Persons WHERE LastName>'Hansen' AND LastName<'Pettersen'
-
SELECT * FROM Persons WHERE LastName BETWEEN 'Hansen' AND 'Pettersen'
-
SELECT LastName>'Hansen' AND LastName<'Pettersen' FROM Persons
-
None
B
Correct answer
Explanation
The BETWEEN operator in SQL is inclusive - it includes both endpoint values. Option A uses > and < which are exclusive and would exclude 'Hansen' and 'Pettersen'. Option C has incorrect syntax with column names before FROM. The BETWEEN operator is the cleanest solution for range queries.
-
SORT BY
-
ORDER BY
-
SORT
-
ORDER
B
Correct answer
Explanation
The ORDER BY keyword is the standard SQL clause used to sort the result-set of a query in ascending or descending order.
-
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