databases Online Quiz - 243
Description: databases Online Quiz - 243 | |
Number of Questions: 22 | |
Created by: Aliensbrain Bot | |
Tags: databases |
Which SQL statement is used to insert new data in a database?
-
INSERT NEW
-
ADD NEW
-
ADD RECORD
-
INSERT INTO
AI Explanation
To answer this question, you need to understand SQL statements for inserting new data into a database.
Let's go through each option to understand why it is correct or incorrect:
Option A) INSERT NEW - This option is incorrect because there is no SQL statement called "INSERT NEW" for inserting new data into a database.
Option B) ADD NEW - This option is incorrect because there is no SQL statement called "ADD NEW" for inserting new data into a database.
Option C) ADD RECORD - This option is incorrect because there is no SQL statement called "ADD RECORD" for inserting new data into a database.
Option D) INSERT INTO - This option is correct because the SQL statement "INSERT INTO" is used to insert new data into a database.
The correct answer is D) INSERT INTO. This option is correct because the "INSERT INTO" statement is commonly used in SQL to add new records to a database table.
With SQL, how do you select a column named 'FirstName' from a table named 'Persons'?
-
SELECT FirstName FROM Persons
-
EXTRACT FirstName FROM Persons
-
SELECT Persons.FirstName
-
SELECT * FROM Persons
AI Explanation
To select a column named 'FirstName' from a table named 'Persons' in SQL, you would use the SELECT statement. Let's go through each option to understand why it is correct or incorrect:
Option A) SELECT FirstName FROM Persons - This option is correct because it uses the SELECT statement to specify the column 'FirstName' that you want to retrieve from the table 'Persons'.
Option B) EXTRACT FirstName FROM Persons - This option is incorrect. The EXTRACT keyword is used to extract parts of a date or time value, not for selecting columns from a table.
Option C) SELECT Persons.FirstName - This option is incorrect. Although it specifies the desired column 'FirstName', it is missing the keyword FROM, which is necessary to indicate the table 'Persons' from which to retrieve the column.
Option D) SELECT * FROM Persons - This option is incorrect. The asterisk (*) symbol is used to select all columns from a table. It does not specifically select only the 'FirstName' column.
The correct answer is A) SELECT FirstName FROM Persons. This option is correct because it uses the SELECT statement to specify the 'FirstName' column from the 'Persons' table.
-
COLLAPSE
-
REMOVE
-
DELETE
-
TRUNCATE
With SQL, how do you select all the columns from a table named 'Persons'?
-
SELECT [all] FROM Persons
-
SELECT * FROM Persons
-
SELECT *.Persons
-
SELECT Persons
With SQL, how do you select all the records from a table named 'Persons' where the value of the column 'FirstName' is 'Peter'?
-
SELECT * FROM Persons WHERE FirstName <> 'Peter'
-
SELECT [all] FROM Persons WHERE FirstName='Peter'
-
SELECT [all] FROM Persons WHERE FirstName LIKE 'Peter'
-
SELECT * FROM Persons WHERE FirstName='Peter'
-
SELECT * FROM Persons WHERE FirstName LIKE 'a%'
-
SELECT * FROM Persons WHERE FirstName LIKE '%a'
-
SELECT * FROM Persons WHERE FirstName='a'
-
SELECT * FROM Persons WHERE FirstName='%a%'
Which SQL statement is used to return only different values?
-
SELECT DISTINCT
-
SELECT DIFFERENT
-
SELECT UNIQUE
-
SELECT ALL
AI Explanation
To answer this question, you need to understand how to filter and retrieve distinct values in a SQL query.
Let's go through each option to understand why it is correct or incorrect:
Option A) SELECT DISTINCT - This option is correct because the "DISTINCT" keyword is used in a SQL SELECT statement to retrieve only unique or different values. It eliminates duplicate rows from the result set.
Option B) SELECT DIFFERENT - This option is incorrect because there is no keyword "DIFFERENT" in SQL that can be used to retrieve distinct values.
Option C) SELECT UNIQUE - This option is incorrect because the "UNIQUE" keyword is not used in SQL to retrieve distinct values. It is used to define a column or set of columns as unique constraints, ensuring that no duplicate values are entered into those columns.
Option D) SELECT ALL - This option is incorrect because the "ALL" keyword is the default behavior in SQL. It is not used to retrieve distinct values. When you use the "SELECT" statement without specifying DISTINCT, it returns all rows, including duplicates.
The correct answer is Option A) SELECT DISTINCT. This option is correct because it is the correct SQL statement to retrieve only different values, eliminating duplicates from the result set.
Which SQL keyword is used to sort the result-set?
-
ORDER
-
ORDER BY
-
SORT BY
-
SORT
AI Explanation
To answer this question, you need to understand how to sort the result-set in SQL.
Option A) ORDER - This option is incorrect because the keyword "ORDER" alone is not used to sort the result-set. It needs to be combined with another keyword.
Option B) ORDER BY - This option is correct. The "ORDER BY" keyword is used in SQL to sort the result-set in ascending or descending order based on one or more columns.
Option C) SORT BY - This option is incorrect because "SORT BY" is not a valid keyword in SQL for sorting the result-set.
Option D) SORT - This option is incorrect because "SORT" is not a valid keyword in SQL for sorting the result-set.
The correct answer is B) ORDER BY. This option is correct because the "ORDER BY" keyword is used to sort the result-set in SQL.
With SQL, how can you return all the records from a table named 'Persons' sorted descending by 'FirstName'?
-
SELECT * FROM Persons ORDER FirstName DESC
-
SELECT * FROM Persons ORDER BY FirstName DESC
-
SELECT * FROM Persons SORT BY 'FirstName' DESC
-
SELECT * FROM Persons SORT 'FirstName' DESC
What is the output? SELECT SUBSTRING('123456', 0, 3)
-
123
-
12
-
123456
-
456
AI Explanation
To answer this question, you need to understand the SUBSTRING
function in SQL.
The SUBSTRING
function is used to extract a substring from a given string. It takes three arguments: the input string, the starting position, and the length of the substring to be extracted.
In this case, the input string is '123456'. The starting position is 0, and the length is 3.
Using these arguments, the SUBSTRING
function will extract a substring starting from the 0th position (which is the first character) with a length of 3 characters.
So, the output of the SUBSTRING('123456', 0, 3)
statement will be '12'.
Therefore, the correct answer is B) 12.
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
-
09/09/2008
-
09-09-2008 00:00:00:000
-
Error Message
-
None of the above
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.
-
4
-
3.56
-
3.564636
-
3
What is the output? DECLARE @val CHAR(20) SET @val = ' SQL is cool ' select LEN(@val)
-
20
-
14
-
12
-
13
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.
what is the len of @c? declare @c varchar(8000) set @c = N'hello' + replicate('-',8000) print len(@c) print @c
-
8000
-
4000
-
4005
-
5
AI Explanation
To determine the length of the variable @c
, we need to understand how the LEN()
function works in SQL.
In SQL, the LEN()
function is used to return the number of characters in a string. It counts the number of characters, including spaces and special characters.
In the given code snippet, the variable @c
is declared as a varchar(8000)
. This means it can hold a maximum of 8000 characters.
The code then sets the value of @c
to N'hello' + replicate('-',8000)
. Here, replicate('-',8000)
is used to repeat the dash symbol "-" 8000 times. The resulting string is concatenated with the string "hello".
Since the LEN()
function counts the number of characters in a string, it will count all the characters in @c
, including the "hello" string and the repeated dashes.
Therefore, the length of @c
will be the sum of the length of "hello" (5 characters) and the length of the repeated dashes (8000 characters).
So the correct answer is:
B. 4000
What is the output? SELECT SUBSTRING('123456', 0, 3)
-
123
-
12
-
123456
-
456
AI Explanation
To answer this question, let's understand the function SUBSTRING()
in SQL.
The SUBSTRING()
function is used to extract a substring from a given string. It takes three parameters: the input string, the starting position of the substring, and the length of the substring.
In the given question, the input string is '123456', the starting position is 0, and the length of the substring is 3.
Using these parameters, the SUBSTRING()
function will extract a substring from the input string starting at position 0 and with a length of 3.
Now, let's go through each option to determine the correct output:
Option A) 123 - This option is incorrect because the starting position is 0, which means the substring will start from the first character of the input string. Therefore, the output will not include the first character '1'.
Option B) 12 - This option is correct. The starting position is 0, so the substring will start from the first character '1'. The length of the substring is 3, so it will include the first two characters '1' and '2'.
Option C) 123456 - This option is incorrect because the length of the substring is 3. Therefore, the output will not include the entire input string.
Option D) 456 - This option is incorrect because the starting position is 0, so the substring will start from the first character '1'. The length of the substring is 3, so it will not include the characters '4', '5', and '6'.
The correct answer is Option B) 12. This option is correct because the substring will start from the first character '1' and have a length of 3, including the characters '1' and '2'.
Which of the following SQL functions can operate on any datatype?
-
to_char
-
max
-
rollup
-
cube
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?
-
Primary key access
-
Full table scan
-
Access via unique index
-
Table access by ROWID
-
None of the above
Which command will delete all data from a table and will not write to the rollback segment?
-
DROP
-
DELETE
-
TRUNCATE
-
REMOVE
-
NONE OF THE ABOVE
AI Explanation
To answer this question, you need to understand the differences between the commands DROP, DELETE, and TRUNCATE in the context of deleting data from a table.
Option A) DROP - This option is incorrect because the DROP command is used to delete an entire table or database object, including its structure. It does not specifically delete data from a table without affecting the rollback segment.
Option B) DELETE - This option is incorrect because the DELETE command is used to delete specific rows from a table based on a condition. It does write to the rollback segment to allow for a rollback operation if needed.
Option C) TRUNCATE - This option is correct because the TRUNCATE command is used to delete all data from a table, but it does not write to the rollback segment. TRUNCATE is a DDL (Data Definition Language) command that is faster than DELETE because it deallocates the data pages and resets the highwater mark, freeing the space for reuse.
Option D) REMOVE - This option is incorrect because the REMOVE command is not a valid command in most database systems.
Option E) NONE OF THE ABOVE - This option is incorrect because option C (TRUNCATE) is the correct answer.
The correct answer is C) TRUNCATE. This option is correct because it deletes all data from a table without writing to the rollback segment.
-
By value
-
By reference
-
By type
-
none of the above
-
Real abstarct clustersl
-
Real application cursors
-
Real application clusters
-
none of the above
Which of the following SQL functions can operate on any datatype?
-
to_char
-
max
-
cube
-
rollup
-
Primary key access
-
Full table scan
-
Access via unique index
-
Table access by ROWID