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 html
  1. True

  2. False

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

To solve this question, the user needs to know what nested tables are.

A nested table is a table that is placed inside another table, and it can be a useful way to organize and display information.

Thus, the correct answer is:

The Answer is: A, True.

Multiple choice sql
  1. Strong Question Language

  2. Structured Question Language

  3. Structured Query Language

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

SQL stands for Structured Query Language. It is the standard language used to communicate with relational database management systems (RDBMS) to perform tasks such as data retrieval and updates.

Multiple choice sql
  1. GET

  2. OPEN

  3. EXTRACT

  4. SELECT

  5. QUERY

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

To extract data from a database using SQL, the correct option is D. SELECT.

Explanation:

The SELECT statement is used to extract or retrieve data from a database. It is one of the most commonly used SQL statements and forms the core of most database queries. The SELECT statement is followed by the columns or fields that need to be retrieved from the table or tables specified in the FROM clause. The WHERE clause can be used to filter the results based on specific conditions.

Let's go through each option and explain why it is right or wrong:

A. GET: This option is not a valid SQL statement. GET is not a SQL keyword and is not used to extract data from a database.

B. OPEN: This option is not used to extract data from a database. OPEN is used to open a cursor variable, which can then be used to fetch data from a result set.

C. EXTRACT: This option is used to extract parts of a date or time value such as year, month, day, hour, minute, or second. It is not used to extract data from a database table.

D. SELECT: This option is the correct answer. The SELECT statement is used to extract or retrieve data from a database.

E. QUERY: This option is not a specific SQL statement. Query is a general term used to refer to any SQL statement that retrieves data from a database. However, it is not a specific SQL keyword used to extract data.

Therefore, the answer is:

The Answer is: D. SELECT

Multiple choice sql
  1. TRUNCATE

  2. DELETE

  3. REMOVE

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

DELETE is the standard SQL DML statement for removing rows from a table, optionally with a WHERE clause for selective deletion. TRUNCATE also removes data but is a DDL operation that clears all rows at once and cannot be rolled back in some databases.

Multiple choice sql
  1. EXTRACT FirstName FROM Persons

  2. SELECT FirstName FROM Persons

  3. SELECT Persons.FirstName

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

To solve this question, the user needs to have a basic understanding of SQL and the syntax used to select specific columns from a table. In SQL, the SELECT statement is used to retrieve data from a database. The user must know how to specify the column name and the table name in the SELECT statement to retrieve the desired data.

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

A. EXTRACT FirstName FROM Persons: This option is incorrect. The EXTRACT keyword is used to retrieve date and time information from a specified value, not to select specific columns from a table.

B. SELECT FirstName FROM Persons: This option is correct. The SELECT statement followed by the column name (FirstName) and the table name (Persons) retrieves the data from the specified column in the specified table.

C. SELECT Persons.FirstName: This option is also correct. The SELECT statement can be written in the format of "SELECT TableName.ColumnName" to specify the table name and column name. In this case, the column name (FirstName) is preceded by the table name (Persons) and separated by a dot (.) to retrieve the desired data.

The Answer is: B

Multiple choice sql
  1. SELECT [all] FROM Persons WHERE FirstName='Peter'

  2. SELECT * FROM Persons WHERE FirstName LIKE 'Peter'

  3. SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter'

  4. SELECT * FROM Persons WHERE FirstName='Peter'

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

Use the = operator for exact value matching in WHERE clauses, with string literals in single quotes. LIKE is only for pattern matching with wildcards (% or _). The asterisk selects all columns.

Multiple choice sql
  1. SELECT * FROM Persons WHERE FirstName='%a%'

  2. SELECT * FROM Persons WHERE FirstName LIKE '%a'

  3. SELECT * FROM Persons WHERE FirstName='a'

  4. SELECT * FROM Persons WHERE FirstName LIKE 'a%'

  5. SELECT * FROM Persons WHERE FirstName='a'"

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

The LIKE operator performs pattern matching where % matches any sequence of characters. 'a%' means starts with 'a' followed by anything. '%a' means ends with 'a', and '%a%' means contains 'a'.

Multiple choice sql
  1. SELECT * FROM Persons WHERE FirstName LIKE 'Peter' AND LastName LIKE 'Jackson'

  2. SELECT * FROM Persons WHERE FirstName='Peter' AND LastName='Jackson'

  3. SELECT FirstName='Peter', LastName='Jackson' FROM Persons

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

Combine multiple exact-match conditions with AND, using = for each exact value. All matching conditions must be in the WHERE clause, not the SELECT clause. LIKE is unnecessary unless you need pattern matching.

Multiple choice sql
  1. SELECT LastName>'Hansen' AND LastName<'Pettersen' FROM Persons

  2. SELECT * FROM Persons WHERE LastName BETWEEN 'Hansen' AND 'Pettersen'

  3. SELECT * FROM Persons WHERE LastName>'Hansen' AND LastName<'Pettersen'

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

The BETWEEN operator selects values within a given range and is inclusive of both endpoints. It is equivalent to using >= and <= combined with AND. BETWEEN works with text, numbers, and dates.

Multiple choice sql
  1. SORT BY

  2. ORDER

  3. ORDER BY

  4. SORT

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

ORDER BY is the standard SQL clause used to sort query results in ascending or descending order. SORT BY and SORT are not valid SQL keywords for this purpose.