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
-
Minus
-
Except
-
Intersect
-
Union
-
NULLIF(X,Y)
-
COALESCE(X,Y)
-
ZEROIFNULL(X,Y)
-
NULLIFZERO(X,Y)
A
Correct answer
Explanation
The NULLIF(X, Y) function compares two expressions. If they are equal, the function returns NULL. If they are not equal, it returns the first expression (X). COALESCE returns the first non-null value in its list.
-
Return Top 3 Row in the Retailer Table
-
Return Error
-
Return No Record
-
Return all Records from Retailer Table
B
Correct answer
Explanation
The subquery 'select top 3 Rtrid from retailer' returns multiple rows, but the WHERE clause uses '=' which expects a single value. Comparing a column to multiple rows with '=' causes an error - you should use 'IN' instead for multiple values.
-
Return Top 3 Row in the Retailer Table
-
Return Error
-
Return No Record
-
Return all Records from Retailer Table
B
Correct answer
Explanation
A relational database table can have only one primary key, which uniquely identifies each record, though that primary key can consist of multiple columns as a composite key.
-
Abs is not a recognized function name
-
-20
-
20
-
None
C
Correct answer
Explanation
The expression 25-45 evaluates to -20, and the ABS() function returns the absolute value, which is 20. ABS is a valid SQL Server function that returns the magnitude of a number.
-
All the Above
-
i) and ii)
-
i), ii) and iii)
-
None
A
Correct answer
Explanation
SQL supports various types of joins to combine rows from two or more tables. Inner Join, Left Outer Join, Cross Join, and Self Join are all standard, valid join types available in SQL, making 'All the Above' the correct choice.
-
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.
-
Min( )
-
Sqrt( )
-
Sum( )
-
max( )
B
Correct answer
Explanation
Group functions (aggregate functions) like MIN(), MAX(), and SUM() operate on multiple rows and return a single result. SQRT() is a scalar function that operates on individual values, returning the square root of a single number, making it the correct answer as 'not a group function'.
-
Open
-
Get
-
Extract
-
None of the Above
D
Correct answer
Explanation
The standard SQL statement used to extract or retrieve data from a database is SELECT. Since SELECT is not listed among the choices, None of the Above is the correct answer.
-
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.