Basic SQL Quiz

Description: Basic SQL Quiz
Number of Questions: 18
Created by:
Tags: sql
Attempted 0/18 Correct 0 Score 0

What does SQL stand for?

sql
  1. Strong Question Language

  2. Structured Question Language

  3. Structured Query Language


Correct Option: C
sql
  1. GET

  2. OPEN

  3. EXTRACT

  4. SELECT

  5. QUERY


Correct Option: D
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

Which SQL statement is used to update data in a database?

sql
  1. UPDATE

  2. SAVE AS

  3. MODIFY

  4. SAVE


Correct Option: A

Which SQL statement is used to delete data from a database?

sql
  1. TRUNCATE

  2. DELETE

  3. REMOVE


Correct Option: B
sql
  1. ADD RECORD

  2. ADD INTO

  3. INSERT

  4. ADD NEW


Correct Option: C
sql
  1. EXTRACT FirstName FROM Persons

  2. SELECT FirstName FROM Persons

  3. SELECT Persons.FirstName


Correct Option: B
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

sql
  1. SELECT [all] FROM Persons

  2. SELECT All Persons

  3. SELECT *.Persons

  4. SELECT * FROM Persons


Correct Option: D
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'


Correct Option: D
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'"


Correct Option: D

The OR operator displays a record if ANY conditions listed are true. The AND operator displays a record if ALL of the conditions listed are true

sql
  1. True

  2. False


Correct Option: A

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) True - This option is correct because the OR operator displays a record if ANY of the conditions listed are true. In other words, if at least one of the conditions is true, the record will be displayed.

Option B) False - This option is incorrect because it contradicts the definition of the OR operator. The OR operator does not require all conditions to be true; it only requires at least one condition to be true.

The correct answer is A) True. This option is correct because it accurately describes the behavior of the OR operator.

sql
  1. True

  2. False


Correct Option: B
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

sql
  1. EXPLICIT

  2. IMPLICIT

  3. EXCLUSIVE

  4. SHARED

  5. READ ONLY


Correct Option: C
sql
  1. True

  2. False


Correct Option: B
Explanation:

To solve this question, the user needs to know the concept of NULL value and its treatment in programming.

The correct answer is:

B. False

Explanation:

In programming, a NULL value represents the absence of a value or an unknown value. It is not the same as a blank or 0. When a variable is assigned a NULL value, it means that no value has been assigned to it or that the value is unknown.

In SQL, for example, NULL values cannot be compared using the equality operator (=) or inequality operator (<>). Instead, you have to use the IS NULL or IS NOT NULL operator to check for NULL values.

Therefore, option B is the correct answer as a NULL value is not treated as a blank or 0.

sql
  1. right

  2. full

  3. right outer

  4. full outer

  5. all of the above


Correct Option: E
- Hide questions