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

Multiple choice sql
  1. SELECT * FROM Persons SORT BY 'FirstName' DESC

  2. SELECT * FROM Persons ORDER BY FirstName DESC

  3. SELECT * FROM Persons ORDER FirstName DESC

  4. SELECT * FROM Persons SORT 'FirstName' DESC

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

ORDER BY is the correct clause for sorting, and DESC specifies descending order. The column name should not be quoted, and the keyword is ORDER BY not SORT BY.

Multiple choice sql
  1. INSERT INTO Persons VALUES ('Jimmy', 'Jackson')

  2. INSERT ('Jimmy', 'Jackson') INTO Persons

  3. INSERT VALUES ('Jimmy', 'Jackson') INTO Persons

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

INSERT INTO table VALUES (values) is the standard SQL syntax for inserting a complete row. The table name must come after INSERT INTO, and VALUES must precede the actual values.

Multiple choice sql
  1. UPDATE Persons SET LastName='Hansen' INTO LastName='Nilsen'

  2. UPDATE Persons SET LastName='Nilsen' WHERE LastName='Hansen'

  3. MODIFY Persons SET LastName='Hansen' INTO LastName='Nilsen

  4. MODIFY Persons SET LastName='Nilsen' WHERE LastName='Hansen'

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

UPDATE table SET column=value WHERE condition is the correct syntax. SET assigns the new value, and WHERE specifies which rows to update based on the old value.

Multiple choice sql
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

To solve this question, one needs to understand the difference between count(*) and count(column_name).

count(*) returns the total number of rows in the table, whereas count(column_name) returns the number of non-null values for the given column.

Now, let's go through each option and explain why it is right or wrong:

A. True: This option is false. count(*) will always return the same value as the number of rows in the table, while count(column_name) will return the number of non-null values for the given column. Thus, it is possible for count(column_name) to return a higher value than count(*), but not a lower value.

B. False: This option is correct. count(*) returns the total number of rows in the table, whereas count(column_name) returns the number of non-null values for the given column. Thus, it is not possible for count(column_name) to return fewer rows than count(*).

The Answer is: B

Multiple choice sql
  1. EXPLICIT

  2. IMPLICIT

  3. EXCLUSIVE

  4. SHARED

  5. READ ONLY

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

An EXCLUSIVE lock is used for data-modification operations. It prevents any other transaction from acquiring any type of lock on the resource (table or page) until the exclusive lock is released, effectively denying all other access.

Multiple choice sql
  1. 2

  2. 3

  3. 7

  4. Statement will generate an error.

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

To solve this question, the user needs to know that the LEFT function extracts a specified number of characters from the left side of a given string. The CAST function converts a given expression to a specified data type. The LEN function returns the number of characters in a given string.

In this case, the LEFT function is extracting the first three characters from the string '026-100', which results in '026'. The CAST function is converting this string to an integer data type, resulting in the value 26. The LEN function then determines the number of characters in the resulting string, which is 2. Therefore, the correct answer is:

The Answer is: B. 2

Multiple choice sql
  1. 1900-01-01 00:00:00.000

  2. 1899-01-01 00:00:00.000

  3. 1752-01-01 00:00:00.000

  4. The system will generate an error. Only positive integer values can be converted to a SMALLDATETIME data type.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

To solve this question, the user needs to know about the SMALLDATETIME data type and how to cast values to it.

In SQL Server, SMALLDATETIME is a data type that stores a date and time with a precision of one minute. It is represented as a two-byte signed integer.

The CAST function is used to convert one data type to another. In this case, the value -1 is being cast to the SMALLDATETIME data type.

Now, let's go through each option and explain why it is right or wrong:

A. 1900-01-01 00:00:00.000: This option is incorrect because the SMALLDATETIME data type has a minimum value of 1900-01-01 00:00:00. The value -1 is less than the minimum value, so it cannot be converted to a SMALLDATETIME.

B. 1899-01-01 00:00:00.000: This option is incorrect because the SMALLDATETIME data type has a minimum value of 1900-01-01 00:00:00. The value -1 is less than the minimum value, so it cannot be converted to a SMALLDATETIME.

C. 1752-01-01 00:00:00.000: This option is incorrect because the SMALLDATETIME data type has a minimum value of 1900-01-01 00:00:00. The value -1 is less than the minimum value, so it cannot be converted to a SMALLDATETIME.

D. The system will generate an error. Only positive integer values can be converted to a SMALLDATETIME data type: This option is incorrect because the SMALLDATETIME data type can store both positive and negative integer values. However, the value -1 is less than the minimum value of the SMALLDATETIME data type, so it cannot be converted to a SMALLDATETIME.

The Answer is: D