0

databases Online Quiz - 243

Description: databases Online Quiz - 243
Number of Questions: 22
Created by:
Tags: databases
Attempted 0/22 Correct 0 Score 0
  1. INSERT NEW

  2. ADD NEW

  3. ADD RECORD

  4. INSERT INTO


Correct Option: D
  1. SELECT FirstName FROM Persons

  2. EXTRACT FirstName FROM Persons

  3. SELECT Persons.FirstName

  4. SELECT * FROM Persons


Correct Option: A

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

  1. COLLAPSE

  2. REMOVE

  3. DELETE

  4. TRUNCATE


Correct Option: C
  1. SELECT [all] FROM Persons

  2. SELECT * FROM Persons

  3. SELECT *.Persons

  4. SELECT Persons


Correct Option: B
Explanation:

To select all the columns from a table named 'Persons' using SQL, the user needs to use the following query:

B. SELECT * FROM Persons

Option A is incorrect because the SQL keyword for selecting all columns is not 'all,' but rather '*'.

Option C is incorrect because the '*' should come before the table name, and not after it.

Option D is incorrect because 'Persons' alone does not specify which columns to select from the table.

Therefore, the correct answer is option B.

  1. SELECT * FROM Persons WHERE FirstName <> 'Peter'

  2. SELECT [all] FROM Persons WHERE FirstName='Peter'

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

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


Correct Option: D
Explanation:

To select all the records from the table named 'Persons' where the value of the column 'FirstName' is 'Peter', the correct SQL query is:

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

Let's go through each option and explain why the other options are incorrect:

A. SELECT * FROM Persons WHERE FirstName <> 'Peter' This query selects all records where the 'FirstName' column is not equal to 'Peter'. It is the opposite of what we want, so this option is incorrect.

B. SELECT [all] FROM Persons WHERE FirstName='Peter' The use of '[all]' is not necessary in this query. It should be replaced with '*' to select all columns. Additionally, the operator '=' should be used instead of 'LIKE' since we are looking for an exact match. Therefore, this option is incorrect.

C. SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter' The 'LIKE' operator is used for pattern matching and allows the use of wildcards (% or _). Since we are looking for an exact match of 'Peter', the '=' operator should be used instead. Therefore, this option is incorrect.

D. SELECT * FROM Persons WHERE FirstName='Peter' This option correctly selects all records from the 'Persons' table where the 'FirstName' column is equal to 'Peter'.

So, the correct answer is: D. SELECT * FROM Persons WHERE FirstName='Peter'

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

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

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

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


Correct Option: A
  1. SELECT DISTINCT

  2. SELECT DIFFERENT

  3. SELECT UNIQUE

  4. SELECT ALL


Correct Option: A
  1. SELECT * FROM Persons ORDER FirstName DESC

  2. SELECT * FROM Persons ORDER BY FirstName DESC

  3. SELECT * FROM Persons SORT BY 'FirstName' DESC

  4. SELECT * FROM Persons SORT 'FirstName' DESC


Correct Option: B
Explanation:

To solve this question, the user needs to know SQL syntax and the concept of sorting query results in a descending order based on a specific column.

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

A. SELECT * FROM Persons ORDER FirstName DESC This option is incorrect because the correct syntax for sorting query results in SQL requires the use of the "ORDER BY" clause followed by the column name to sort by, and then the keyword "DESC" to specify descending order. Therefore, the correct syntax should be "ORDER BY FirstName DESC" instead of "ORDER FirstName DESC".

B. SELECT * FROM Persons ORDER BY FirstName DESC This option is correct. The "ORDER BY" clause is used to sort the query results based on a specific column. In this case, we want to sort the results in descending order based on the "FirstName" column. Therefore, the correct syntax is "ORDER BY FirstName DESC".

C. SELECT * FROM Persons SORT BY 'FirstName' DESC This option is incorrect because there is no "SORT" keyword in SQL. The correct keyword to use is "ORDER BY". Additionally, the column name should not be enclosed in single quotes. Therefore, the correct syntax should be "ORDER BY FirstName DESC" instead of "SORT BY 'FirstName' DESC".

D. SELECT * FROM Persons SORT 'FirstName' DESC This option is incorrect because the correct keyword to use for sorting query results in SQL is "ORDER BY" rather than "SORT". Additionally, the column name should not be enclosed in single quotes. Therefore, the correct syntax should be "ORDER BY FirstName DESC" instead of "SORT 'FirstName' DESC".

The Answer is: B

What would be the output of the code below in SQL Server 2005 and earlier versions? declare @d date select @d = '09/09/2008' select @d

  1. 09/09/2008

  2. 09-09-2008 00:00:00:000

  3. Error Message

  4. None of the above


Correct Option: C

AI Explanation

To answer this question, you need to understand how SQL Server 2005 and earlier versions handle the date data type.

In SQL Server 2005 and earlier versions, the date data type is not available. Instead, you can use the datetime data type to store both date and time values.

In the given code, the variable @d is declared as a date type. However, the value assigned to it is a string '09/09/2008'.

Since the date data type is not available in SQL Server 2005 and earlier versions, trying to assign a string value to a date variable will result in an error.

Therefore, the correct answer is C) Error Message.

What is the output? declare @d decimal select @d = 3.564636 select @d

  1. 4

  2. 3.56

  3. 3.564636

  4. 3


Correct Option: A

What is the output? DECLARE @val CHAR(20) SET @val = ' SQL is cool ' select LEN(@val)

  1. 20

  2. 14

  3. 12

  4. 13


Correct Option: C

AI Explanation

To answer this question, you need to understand the LEN function in SQL.

The LEN function is used to return the number of characters in a specified string. In this case, the specified string is the variable @val, which is set to ' SQL is cool '.

The LEN function will count all characters in the string, including leading and trailing spaces. Therefore, the output of the query select LEN(@val) will be the total number of characters in the string, which is 12.

So, the correct answer is C) 12.

Which of the following SQL functions can operate on any datatype?

  1. to_char

  2. max

  3. rollup

  4. cube


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) to_char - This option is correct because the to_char function in SQL can operate on any datatype. It is used to convert a value of any datatype to a character string.

Option B) max - This option is incorrect because the max function in SQL is used to return the maximum value of a specified column. It operates on numeric data types, not any datatype.

Option C) rollup - This option is incorrect because the rollup function in SQL is used to generate subtotals and grand totals in a result set. It operates on grouping sets, not any datatype.

Option D) cube - This option is incorrect because the cube function in SQL is used to generate all possible combinations of a specified set of expressions. It operates on grouping sets, not any datatype.

The correct answer is Option A) to_char. This option is correct because the to_char function can operate on any datatype and convert it to a character string.

Which Oracle access method is the fastest way for Oracle to retrieve a single row?

  1. Primary key access

  2. Full table scan

  3. Access via unique index

  4. Table access by ROWID

  5. None of the above


Correct Option: A
  1. By value

  2. By reference

  3. By type

  4. none of the above


Correct Option: A
  1. Real abstarct clustersl

  2. Real application cursors

  3. Real application clusters

  4. none of the above


Correct Option: A

Which of the following SQL functions can operate on any datatype?

  1. to_char

  2. max

  3. cube

  4. rollup


Correct Option: B
Explanation:

To answer this question, the user needs to have knowledge of SQL functions.

A. to_char: This function is used to convert a number or date to a string. It cannot operate on any datatype.

B. max: This function returns the maximum value in a set of values. It can operate on any datatype.

C. cube: This function is used to generate a result set that represents the subtotals and grand totals of the selected columns. It cannot operate on any datatype.

D. rollup: This function is used to generate a result set that represents the subtotals of the selected columns. It cannot operate on any datatype.

Therefore, the correct answer is:

The Answer is: B. max

Which Oracle access method is the fastest way for Oracle to retrieve a single row?

  1. Primary key access

  2. Full table scan

  3. Access via unique index

  4. Table access by ROWID


Correct Option: D
- Hide questions