Basic SQL Quiz

Description: Basic SQL Quiz
Number of Questions: 18
Created by:
Tags: sql
Attempted 0/18 Correct 0 Score 0
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

Which SQL statement is used to insert new data in a database?

sql
  1. ADD RECORD

  2. ADD INTO

  3. INSERT

  4. ADD NEW


Correct Option: C

AI Explanation

To answer this question, you need to understand the SQL statement used to insert new data into a database. Let's go through each option to understand why it is correct or incorrect:

Option A) ADD RECORD - This option is incorrect because there is no SQL statement called "ADD RECORD" for inserting new data into a database.

Option B) ADD INTO - This option is incorrect because there is no SQL statement called "ADD INTO" for inserting new data into a database.

Option C) INSERT - This option is correct because the SQL statement "INSERT" is used to insert new data into a database. The syntax for the INSERT statement is as follows:

INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

Option D) ADD NEW - This option is incorrect because there is no SQL statement called "ADD NEW" for inserting new data into a database.

The correct answer is C) INSERT. This option is correct because the SQL statement "INSERT" is used to insert new data into a database.

With SQL, how do you select a column named "FirstName" from a table named "Persons"?

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

With SQL, how do you select all the columns from a table named "Persons"?

sql
  1. SELECT [all] FROM Persons

  2. SELECT All Persons

  3. SELECT *.Persons

  4. SELECT * FROM Persons


Correct Option: D

AI Explanation

To select all the columns from a table named "Persons" in SQL, you would use the following syntax:

D. SELECT * FROM Persons

Option A) SELECT [all] FROM Persons - This option is incorrect because the correct syntax to select all columns is to use an asterisk (*) symbol.

Option B) SELECT All Persons - This option is incorrect because it doesn't follow the correct syntax. The keyword "All" should not be used to select all columns.

Option C) SELECT .Persons - This option is incorrect because the dot (.) operator is used to specify a column from a table, not to select all columns. The correct syntax to select all columns is to use an asterisk () symbol.

Option D) SELECT * FROM Persons - This option is correct because it uses the correct syntax to select all columns from the "Persons" table. The asterisk (*) symbol represents all columns in the table.

Therefore, the correct answer is D. SELECT * FROM Persons.

With SQL, how do you select all the records from a table named "Persons" where the value of the column "FirstName" is "Peter"?

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

AI Explanation

To select all the records from a table named "Persons" where the value of the column "FirstName" is "Peter", you would use the following SQL query:

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

Let's go through each option to understand why it is correct or incorrect:

Option A) SELECT [all] FROM Persons WHERE FirstName='Peter' This option is incorrect because the keyword "all" is not needed to select all records. The asterisk (*) symbol is used to select all columns.

Option B) SELECT * FROM Persons WHERE FirstName LIKE 'Peter' This option is incorrect because the "LIKE" keyword is used for pattern matching, not for exact matches. In this case, we need an exact match, so the "=" operator should be used instead of "LIKE".

Option C) SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter' Similar to Option A, this option is incorrect because the keyword "all" is not needed to select all records. The asterisk (*) symbol is used to select all columns.

Option D) SELECT * FROM Persons WHERE FirstName='Peter' This option is correct because it selects all columns (*) from the "Persons" table where the value of the "FirstName" column is exactly "Peter".

The correct answer is D.

With SQL, how do you select all the records from a table named "Persons" where the value of the column "FirstName" starts with an "a"?

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

AI Explanation

To select all the records from a table named "Persons" where the value of the column "FirstName" starts with an "a", you can use the LIKE operator with the 'a%' pattern.

Let's go through each option to understand why it is correct or incorrect:

Option A) SELECT * FROM Persons WHERE FirstName='%a%' - This option is incorrect because the '%' wildcard should be placed at the end of the pattern to match any characters after 'a'.

Option B) SELECT * FROM Persons WHERE FirstName LIKE '%a' - This option is incorrect because the '%' wildcard should be placed at the beginning of the pattern to match any characters before 'a'.

Option C) SELECT * FROM Persons WHERE FirstName='a' - This option is incorrect because it only selects the records where the FirstName column has the exact value of 'a', not the ones that start with 'a'.

Option D) SELECT * FROM Persons WHERE FirstName LIKE 'a%' - This option is correct because it uses the '%' wildcard at the end of the pattern to match any characters after 'a', effectively selecting all the records where the FirstName column starts with 'a'.

Option E) SELECT * FROM Persons WHERE FirstName='a'" - This option is incorrect because it only selects the records where the FirstName column has the exact value of 'a', not the ones that start with 'a'.

The correct answer is Option D. This option is correct because it uses the LIKE operator with the 'a%' pattern to select all the records where the value of the column "FirstName" starts with an "a".

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.

Given an employees table as follows: empid name managerid a1 bob NULL b1 jim a1 B2 tom a1 What value will select count(*) from employees return?

sql
  1. 1

  2. 2

  3. 3

  4. none of the above


Correct Option: C

AI Explanation

To determine the value that will be returned by the query select count(*) from employees, let's analyze the given employees table:

empid | name | managerid
------------------------
a1    | bob  | NULL
b1    | jim  | a1
B2    | tom  | a1

The query select count(*) from employees counts the number of rows in the employees table. It does not consider NULL values.

In this case, there are three rows in the table: (a1, bob, NULL), (b1, jim, a1), and (B2, tom, a1). Therefore, the query will return a value of 3.

Therefore, the correct answer is C) 3.

Sometimes the expression "select count(*)" will return fewer rows than the expression "select count(value)".

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

What type of lock will deny users any access to a table?

sql
  1. EXPLICIT

  2. IMPLICIT

  3. EXCLUSIVE

  4. SHARED

  5. READ ONLY


Correct Option: C

Which of the following is the correct SQL statement to use to remove rows from a table?

sql
  1. DROP

  2. REMOVE ROW

  3. DELETE

  4. DELETE ROW


Correct Option: C

AI Explanation

To remove rows from a table in SQL, the correct statement to use is the DELETE statement. Let's go through each option to understand why it is correct or incorrect:

Option A) DROP - The DROP statement is used to delete an entire table or database, not specific rows within a table. Therefore, this option is incorrect.

Option B) REMOVE ROW - There is no specific SQL statement called REMOVE ROW. Therefore, this option is incorrect.

Option C) DELETE - The DELETE statement is used to remove one or more rows from a table based on a specific condition. It allows you to specify a WHERE clause to determine which rows should be deleted. This is the correct statement to use for removing rows from a table. Therefore, this option is correct.

Option D) DELETE ROW - There is no specific SQL statement called DELETE ROW. Therefore, this option is incorrect.

The correct answer is C) DELETE. This option is correct because the DELETE statement is used to remove one or more rows from a table based on a specific condition.

The only way to join two tables is by using standard, ANSI syntax.

sql
  1. True

  2. False


Correct Option: B

AI Explanation

To answer this question, you need to understand the different ways to join tables in SQL.

Option A) True - This option is incorrect because there are multiple ways to join tables in SQL, not just by using standard ANSI syntax. Other join types include INNER JOIN, OUTER JOIN (LEFT, RIGHT, FULL), CROSS JOIN, etc.

Option B) False - This option is correct because it acknowledges that the only way to join two tables is not limited to standard ANSI syntax. SQL provides various join types and syntax options to join tables based on the specific requirements of the query.

The correct answer is B) False. This option is correct because there are multiple ways to join tables in SQL, not just by using standard ANSI syntax.

A NULL value is treated as a blank or 0.

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.

The left outer join is one type of outer join. Another one is the.

sql
  1. right

  2. full

  3. right outer

  4. full outer

  5. all of the above


Correct Option: E
- Hide questions