databases Online Quiz - 99
Description: databases Online Quiz - 99 | |
Number of Questions: 20 | |
Created by: Aliensbrain Bot | |
Tags: databases |
Select invalid variable types
-
VARCHAR2
-
VARCHAR1
-
CHAR
-
CHAR2
-
INTEGER
-
NUMBER
SELECT ROUND (-123.39953,-2) FROM DUAL;
-
-123.40
-
-100
-
-120
-
-123.30
SELECT ROUND(-123.39953,-3) FROM DUAL;
-
0
-
100
-
123
-
-123
AI Explanation
To answer this question, we need to understand the ROUND function in SQL.
The ROUND function is used to round a number to a specified number of decimal places or to the nearest whole number. It takes two arguments: the number to be rounded and the number of decimal places to round to.
In this case, the number to be rounded is -123.39953 and the number of decimal places to round to is -3.
When rounding to -3 decimal places, we are rounding to the nearest thousands place.
The correct answer is A) 0.
This is because -123.39953, when rounded to the nearest thousands place, becomes 0.
SELECT CONCAT(SUBSTR('MINDWORKS',-5,6),SUBSTR('KNOWMAX',-3,4)) FROM DUAL;
-
KNOWMIND
-
WORKSM
-
WORKSMAX
-
MAXWORKS
AI Explanation
To answer this question, let's break down the query step by step:
The given query is:
SELECT CONCAT(SUBSTR('MINDWORKS',-5,6),SUBSTR('KNOWMAX',-3,4)) FROM DUAL;
SUBSTR('MINDWORKS',-5,6)
:- This function extracts a substring from the string 'MINDWORKS'.
- The starting point (-5) specifies that the substring should start from the 5th character from the end of the string.
- The length (6) specifies that the substring should have a length of 6 characters.
- Therefore, this expression returns 'WORKS'.
SUBSTR('KNOWMAX',-3,4)
:- This function extracts a substring from the string 'KNOWMAX'.
- The starting point (-3) specifies that the substring should start from the 3rd character from the end of the string.
- The length (4) specifies that the substring should have a length of 4 characters.
- Therefore, this expression returns 'MAX'.
CONCAT(SUBSTR('MINDWORKS',-5,6),SUBSTR('KNOWMAX',-3,4))
:- This function concatenates the two substrings obtained from the previous steps.
- The result of the concatenation is 'WORKSMAX'.
Therefore, the correct answer is option C) WORKSMAX.
SELECT DECODE('MINDWORKS','WORKS','MINDWORK','KNOWMAX') FROM DUAL;
-
KNOWMAX
-
MINDWORKS
-
WORKS
-
MINDWORK
How many columns are presented after executing this query: SELECT address1||','||address2||','||address2 "Adress" FROM employee;
-
1
-
2
-
3
-
0
-
4
AI Explanation
To determine the number of columns presented after executing the given query, let's break down the query and analyze it step by step:
The query is: SELECT address1||','||address2||','||address2 "Adress" FROM employee;
Here, we are selecting three columns: address1, address2, and address2 (renamed as "Address" using the alias "Adress"). Each column is concatenated with a comma (',').
So, the query will produce three columns: address1, address2, and Address.
Therefore, the correct answer is C) 3.
-
Primary key access
-
Access via unique index
-
Table access by ROWID
-
Full table scan
You need to modify the STUDENTS table to add a primary key on the STUDENT_ID column. The table is currently empty. Which statement accomplishes this task?
-
ALTER TABLE students ADD PRIMARY KEY student_id;
-
ALTER TABLE students ADD CONSTRAINT PRIMARY KEY (student_id);
-
ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY student_id;
-
ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY (student_id);
-
ALTER TABLE students MODIFY CONSTRAINT stud_id_pk PRIMARY KEY (student_id);
AI Explanation
To add a primary key on the STUDENT_ID column in the STUDENTS table, you can use the following statement:
D. ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY (student_id);
Explanation for each option:
A. ALTER TABLE students ADD PRIMARY KEY student_id; This option is incorrect because it is missing the CONSTRAINT keyword before PRIMARY KEY.
B. ALTER TABLE students ADD CONSTRAINT PRIMARY KEY (student_id); This option is incorrect because it is missing a name for the constraint. A constraint must have a unique name.
C. ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY student_id; This option is incorrect because it is missing parentheses around the column name student_id.
D. ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY (student_id); This option is correct because it uses the correct syntax to add a constraint with a name (stud_id_pk) on the column student_id as the primary key.
E. ALTER TABLE students MODIFY CONSTRAINT stud_id_pk PRIMARY KEY (student_id); This option is incorrect because MODIFY CONSTRAINT is used to modify an existing constraint, not to add a new constraint.
The correct answer is D. ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY (student_id). This option is correct because it adds a primary key constraint with the name stud_id_pk on the column student_id in the STUDENTS table.
Which three are DATETIME data types that can be used when specifying column definitions? (Choose three.)
-
TIMESTAMP
-
INTERVAL MONTH TO DAY
-
INTERVAL DAY TO SECOND
-
INTERVAL YEAR TO MONTH
-
TIMESTAMP WITH DATABASE TIMEZONE
AI Explanation
To answer this question, we need to understand the different DATETIME data types that can be used when specifying column definitions. Let's go through each option to understand which ones are correct:
Option A) TIMESTAMP - This option is correct. TIMESTAMP is a DATETIME data type that represents a date and time value.
Option B) INTERVAL MONTH TO DAY - This option is incorrect. INTERVAL MONTH TO DAY is not a DATETIME data type. It is a data type used to represent an interval of time in terms of months and days.
Option C) INTERVAL DAY TO SECOND - This option is correct. INTERVAL DAY TO SECOND is a DATETIME data type used to represent an interval of time in terms of days, hours, minutes, and seconds.
Option D) INTERVAL YEAR TO MONTH - This option is correct. INTERVAL YEAR TO MONTH is a DATETIME data type used to represent an interval of time in terms of years and months.
Option E) TIMESTAMP WITH DATABASE TIMEZONE - This option is incorrect. TIMESTAMP WITH DATABASE TIMEZONE is not a DATETIME data type. It is a TIMESTAMP data type that includes the database time zone.
The correct answers are A) TIMESTAMP, C) INTERVAL DAY TO SECOND, and D) INTERVAL YEAR TO MONTH. These three options are correct because they are DATETIME data types that can be used when specifying column definitions.
Evaluate the set of SQL statements: CREATE TABLE dept (deptno NUMBER(2), dname VARCNAR2(14), loc VARCNAR2(13)); ROLLBACK; DESCRIBE DEPT What is true about the set?
-
The DESCRIBE DEPT statement displays the structure of the DEPT table.
-
The ROLLBACK statement frees the storage space occupies by the DEPT table.
-
The DESCRIBE DEPT statement returns an error ORA-04043: object DEPT does not exist.
-
The DESCRIBE DEPT statement displays the structure of the DEPT table only if there is a COMMIT statement introduced before the ROLLBACK statement.
AI Explanation
To answer this question, let's go through each option to understand why it is correct or incorrect:
Option A) The DESCRIBE DEPT statement displays the structure of the DEPT table. This option is correct because the DESCRIBE statement is used to display the structure of a table, and in this case, it will display the structure of the DEPT table.
Option B) The ROLLBACK statement frees the storage space occupied by the DEPT table. This option is incorrect. The ROLLBACK statement is used to undo transactions and restore the database to the state it was in before the transaction was initiated. It does not free the storage space occupied by the table.
Option C) The DESCRIBE DEPT statement returns an error ORA-04043: object DEPT does not exist. This option is incorrect. Since the CREATE TABLE statement is executed before the DESCRIBE statement, the DEPT table will exist, and the DESCRIBE statement will be able to display its structure.
Option D) The DESCRIBE DEPT statement displays the structure of the DEPT table only if there is a COMMIT statement introduced before the ROLLBACK statement. This option is incorrect. The DESCRIBE statement does not depend on the presence of a COMMIT statement before the ROLLBACK statement. It will display the structure of the DEPT table regardless of whether a COMMIT statement was used or not.
The correct answer is A. The DESCRIBE DEPT statement displays the structure of the DEPT table.
Which data dictionary table should you query to view the object privileges granted to the user on specific columns?
-
USER_TAB_PRIVS_MADE
-
USER_TAB_PRIVS
-
USER_COL_PRIVS_MADE
-
USER_COL_PRIVS
AI Explanation
To view the object privileges granted to the user on specific columns, you should query the USER_COL_PRIVS data dictionary table.
Let's go through each option to understand why it is correct or incorrect:
Option A) USER_TAB_PRIVS_MADE - This option is incorrect because the USER_TAB_PRIVS_MADE table provides information about the object privileges the user has granted to other users, not the privileges granted to the user on specific columns.
Option B) USER_TAB_PRIVS - This option is incorrect because the USER_TAB_PRIVS table provides information about the object privileges granted to the user on tables, not specific columns.
Option C) USER_COL_PRIVS_MADE - This option is incorrect because the USER_COL_PRIVS_MADE table provides information about the column privileges the user has granted to other users, not the privileges granted to the user on specific columns.
Option D) USER_COL_PRIVS - This option is correct because the USER_COL_PRIVS table provides information about the column privileges granted to the user, including the privileges granted on specific columns of tables.
The correct answer is D. This option is correct because querying the USER_COL_PRIVS table allows you to view the object privileges granted to the user on specific columns.
The EMP table contains these columns: LAST NAME VARCHAR2(25) SALARY NUMBER(6,2) DEPARTMENT_ID NUMBER(6) You need to display the employees who have not been assigned to any department. You write the SELECT statement: SELECT LAST_NAME, SALARY, DEPARTMENT_ID FROM EMP WHERE DEPARTMENT_ID = NULL; What is true about this SQL statement?
-
The SQL statement displays the desired results.
-
The column in the WHERE clause should be changed to display the desired results.
-
The operator in the WHERE clause should be changed to display the desired results.
-
The WHERE clause should be changed to use an outer join to display the desired results.
AI Explanation
To answer this question, let's analyze the given SQL statement:
SELECT LAST_NAME, SALARY, DEPARTMENT_ID FROM EMP WHERE DEPARTMENT_ID = NULL;
The statement is attempting to display the employees who have not been assigned to any department. However, the statement is incorrect.
The correct comparison operator to check for a null value is not the equality operator (=), but rather the "IS NULL" operator. Therefore, option C is correct:
C. The operator in the WHERE clause should be changed to display the desired results.
The correct SQL statement should be:
SELECT LAST_NAME, SALARY, DEPARTMENT_ID FROM EMP WHERE DEPARTMENT_ID IS NULL;
-
0
-
1
-
0.00
-
An error statement
To evaluate the SQL statement, we need to understand the functions ROUND, TRUNC and MOD.
ROUND: rounds a number to a specified number of decimal places. If the second argument is negative, it rounds to the left of the decimal point. For example, ROUND(123.456, 2) = 123.46, ROUND(123.456, -1) = 120. TRUNC: truncates a number to a specified number of decimal places. If the second argument is negative, it truncates to the left of the decimal point. For example, TRUNC(123.456, 2) = 123.45, TRUNC(123.456, -1) = 120. MOD: returns the remainder of a division operation. For example, MOD(7, 3) = 1, MOD(1600, 10) = 0. Using these functions, we can evaluate the SQL statement step by step:
MOD(1600,10) returns 0, since there is no remainder when dividing 1600 by 10. TRUNC(0,-1) returns 0, since there is nothing to truncate to the left of the decimal point. ROUND(0,2) returns 0, since there is nothing to round to the right of the decimal point. Therefore, the final result displayed by the SQL statement is 0.
-
NOT NULL
-
PRIMARY KEY
-
FOREIGN KEY
-
CHECK
-
UNIQUE KEY
Which two are true about aggregate functions? (Choose two.)
-
You can use aggregate functions in any clause of a SELECT statement.
-
You can use aggregate functions only in the column list of the SELECT clause and in the WHERE clause of a SELECT statement.
-
You can mix single row columns with aggregate functions in the column list of a SELECT statement by grouping on the single row columns.
-
You can pass column names, expressions, constants, or functions as parameters to an aggregate function.
-
You can use aggregate functions on a table, only by grouping the whole table as one single group.
-
You cannot group the rows of a table by more than one column while using aggregate functions.
AI Explanation
To answer this question, let's go through each option to understand why it is correct or incorrect:
Option A) You can use aggregate functions in any clause of a SELECT statement. - This option is incorrect because aggregate functions can only be used in the SELECT clause and in the HAVING clause of a SELECT statement.
Option B) You can use aggregate functions only in the column list of the SELECT clause and in the WHERE clause of a SELECT statement. - This option is incorrect because aggregate functions can also be used in the HAVING clause of a SELECT statement.
Option C) You can mix single row columns with aggregate functions in the column list of a SELECT statement by grouping on the single row columns. - This option is correct. When using aggregate functions, you can include both single row columns and aggregate functions in the column list of a SELECT statement by grouping on the single row columns.
Option D) You can pass column names, expressions, constants, or functions as parameters to an aggregate function. - This option is correct. Aggregate functions can take column names, expressions, constants, or functions as parameters.
Option E) You can use aggregate functions on a table, only by grouping the whole table as one single group. - This option is incorrect. Aggregate functions can be used on a table by grouping the data based on specific columns, not necessarily the whole table as one group.
Option F) You cannot group the rows of a table by more than one column while using aggregate functions. - This option is incorrect. You can group the rows of a table by more than one column while using aggregate functions. This allows for more specific aggregation based on multiple criteria.
The correct answers are Option C and Option D.
Which two statements about subqueries are true? (Choose two.)
-
A single row subquery can retrieve data from only one table.
-
A SQL query statement cannot display data from table B that is referred to in its subquery, unless table B is included in the main query's FROM clause.
-
A SQL query statement can display data from table B that is referred to in its subquery, without including table B in its own FROM clause.
-
A single row subquery can retrieve data from more than one table.
-
A single row subquery cannot be used in a condition where the LIKE operator is used for comparison.
-
A multiple-row subquery cannot be used in a condition where the LIKE operator is used for comparison.
AI Explanation
To answer this question, we need to understand the concept of subqueries.
A subquery is a query that is nested within another query. It is used to retrieve data from one or more tables and is enclosed within parentheses.
Let's go through each option to understand which are true about subqueries:
Option A) A single row subquery can retrieve data from only one table. This statement is false. A single row subquery can retrieve data from multiple tables as long as they are related through a common column.
Option B) A SQL query statement cannot display data from table B that is referred to in its subquery unless table B is included in the main query's FROM clause. This statement is true. When a subquery references a table, that table must be included in the main query's FROM clause for the data to be displayed.
Option C) A SQL query statement can display data from table B that is referred to in its subquery without including table B in its own FROM clause. This statement is false. To display data from table B that is referred to in a subquery, table B must be included in the main query's FROM clause.
Option D) A single row subquery can retrieve data from more than one table. This statement is true. A single row subquery can retrieve data from multiple tables if they are related through a common column.
Option E) A single row subquery cannot be used in a condition where the LIKE operator is used for comparison. This statement is false. A single row subquery can be used in a condition where the LIKE operator is used for comparison.
Option F) A multiple-row subquery cannot be used in a condition where the LIKE operator is used for comparison. This statement is false. A multiple-row subquery can be used in a condition where the LIKE operator is used for comparison.
Based on the explanations above, the two true statements about subqueries are:
B. A SQL query statement cannot display data from table B that is referred to in its subquery unless table B is included in the main query's FROM clause. D. A single row subquery can retrieve data from more than one table.
Therefore, the correct answer is B and D.
-
MERGE
-
INSERT
-
UPDATE
-
ADD
-
ENTER
-
You cannot enter the phone numbers for the existing employee records.
-
Both tables have NULL values.
-
You want all unmatched data from one table.
-
You want all matched data from both tables.
-
You want all unmatched data from both tables.
-
One of the tables has more data than the other.
-
You want all matched and unmatched data from only one table.
To answer this question, the user must know the different types of joins in SQL.
- INNER JOIN: returns only matched data from both tables.
- LEFT OUTER JOIN: returns all data from the left table and matched data from the right table.
- RIGHT OUTER JOIN: returns all data from the right table and matched data from the left table.
- FULL OUTER JOIN: returns all matched and unmatched data from both tables.
Now, let's go through each option and determine whether it is a valid case to use a FULL OUTER JOIN:
A. Both tables have NULL values.
- This option is not a determining factor in deciding to use a FULL OUTER JOIN.
B. You want all unmatched data from one table.
- This option does not require a FULL OUTER JOIN, as a LEFT OUTER JOIN or RIGHT OUTER JOIN would suffice depending on which table has the unmatched data.
C. You want all matched data from both tables.
- This option requires an INNER JOIN, not a FULL OUTER JOIN.
D. You want all unmatched data from both tables.
- This option requires a FULL OUTER JOIN, as it returns all matched and unmatched data from both tables.
E. One of the tables has more data than the other.
- This option does not necessarily require a FULL OUTER JOIN, as a LEFT OUTER JOIN or RIGHT OUTER JOIN could also be used depending on which table has more data.
F. You want all matched and unmatched data from only one table.
- This option does not require a FULL OUTER JOIN, as a LEFT OUTER JOIN or RIGHT OUTER JOIN could be used depending on which table has the data.
Therefore, the correct answer is:
The Answer is: D
-
A role can be given to a maximum of 1000 users.
-
A user can have access to a maximum of 10 roles.
-
A role can have a maximum of 100 privileges contained in it.
-
Privileges are given to a role by using the CREATE ROLE statement.
-
A role is a named group of related privileges that can be granted to the user.
-
A user can have access to several roles, and several users can be assigned the same role.
What is necessary for your query on an existing view to execute successfully?
-
The underlying tables must have data.
-
You need SELECT privileges on the view.
-
The underlying tables must be in the same schema.
-
You need SELECT privileges only on the underlying tables.
AI Explanation
To answer this question, you need to understand the concept of views in databases.
A view is a virtual table that is based on the result of a query. It does not store any data itself but instead retrieves data from the underlying tables whenever it is accessed.
Now let's go through each option to understand why it is correct or incorrect:
Option A) The underlying tables must have data - This option is incorrect because a view can still be executed successfully even if the underlying tables do not have data. The view will return an empty result set in such cases.
Option B) You need SELECT privileges on the view - This option is incorrect because having SELECT privileges on the view alone is not sufficient for the query to execute successfully. You also need SELECT privileges on the underlying tables from which the view is derived.
Option C) The underlying tables must be in the same schema - This option is incorrect because the underlying tables can be in different schemas and the view can still be executed successfully. The schema of the view itself is what matters.
Option D) You need SELECT privileges only on the underlying tables - This option is correct. In order to execute a query on an existing view successfully, you need to have SELECT privileges on the underlying tables from which the view is derived. This is because the view retrieves data from these tables when it is accessed.
The correct answer is D) You need SELECT privileges only on the underlying tables. This option is correct because having SELECT privileges on the underlying tables is necessary for the query on the view to execute successfully.