1Z0-051 Demo and Sample
Note: Answers are below each question.
Samples are taken from full version.
View the Exhibits and examine the structures of the PRODUCTS and SALES tables. Which two SQL statements would give the same output? (Choose two.)
SELECT prod_id FROM products INTERSECT
SELECT prod_id FROM sales; B.
SELECT prod_id FROM products MINUS
SELECT prod_id FROM sales; C.
SELECT DISTINCT p.prod_id FROM products p JOIN sales s ON p.prod_id=s.prod_id;
SELECT DISTINCT p.prod_id FROM products p JOIN sales s ON p.prod_id <> s.prod_id;
Answer: A, C
View the Exhibit and examine the structure of the ORDERS and CUSTOMERS tables.
Evaluate the following SQL command: SQL> SELECT o.order_id, c.cust_name, o.order_total, c.credit_limit FROM orders o JOIN customers c USING (customer_id) WHERE o.order_total > c.credit_limit FOR UPDATE ORDER BY o.order_id; Which two statements are true regarding the outcome of the above query? (Choose two.)
It locks all the rows that satisfy the condition in the statement.
It locks only the columns that satisfy the condition in both the tables.
The locks are released only when a COMMIT or ROLLBACK is issued.
The locks are released after a DML statement is executed on the locked rows.
Answer: A, C
FOR UPDATE Clause in a SELECT Statement
Locks the rows in the EMPLOYEES table where job_id is SA_REP.
Lock is released only when you issue a ROLLBACK or a COMMIT.
If the SELECT statement attempts to lock a row that is locked by another user, the database waits until the row is available, and then returns the results of the SELECTstatement SELECT employee_id, salary, commission_pct, job_id FROM employees WHERE job_id = 'SA_REP' FOR UPDATE ORDER BY employee_id;
Which statements are true regarding the FOR UPDATE clause in a SELECT statement? (Choose all that apply.)
It locks only the columns specified in the SELECT list.
It locks the rows that satisfy the condition in the SELECT statement.
It can be used only in SELECT statements that are based on a single table.
It can be used in SELECT statements that are based on a single or multiple tables.
After it is enforced by a SELECT statement, no other query can access the same rows until a COMMIT or ROLLBACK is issued.
Answer: B, D
FOR UPDATE Clause in a SELECT Statement Locks the rows in the EMPLOYEES
table where job_id is SA_REP. Lock is released only when you issue a ROLLBACK or a COMMIT. If the SELECT statement attempts to lock a row that is locked by another user, the database waits until the row is available, and then returns the results of the SELECT statement. FOR UPDATE Clause in a SELECT Statement When you issue a SELECT statement against the database to query some records, no locks are placed on the selected rows. In general, this is required because the number of records locked at any given time is (by default) kept to the absolute minimum: only those records that have been changed but not yet committed are locked. Even then, others will be able to read those records as they appeared before the change (the “before image” of the data). There are times, however, when you may want to lock a set of records even before you change them in your program. Oracle offers the FOR UPDATE clause of the SELECT statement to perform this locking. When you issue a SELECT...FOR UPDATE statement, the relational database management system (RDBMS) automatically obtains exclusive row-level locks on all the rows identified by the SELECT statement, thereby holding the records “for your changes only.” No one else will be able to change any of these records until you perform a ROLLBACK or a COMMIT. You can append the optional keyword NOWAIT to the FOR UPDATE clause to tell the Oracle server not to wait if the table has been locked by another user. In this case, control will be returned immediately to your program or to your SQL Developer environment so that you can perform other work, or simply wait for a period of time before trying again. Without the NOWAIT clause, your process will block until the table is available, when the locks are released by the other user through the issue of a COMMIT or a ROLLBACK command.
View the exhibit and examine the description for the SALES and CHANNELS tables.
You issued the following SQL statement to insert a row in the SALES table: INSERT INTO sales VALUES (23, 2300, SYSDATE, (SELECT channel_id FROM channels WHERE channel_desc='Direct Sales'), 12, 1, 500); Which statement is true regarding the execution of the above statement?
The statement will execute and the new row will be inserted in the SALES table.
The statement will fail because subquery cannot be used in the VALUES clause.
The statement will fail because the VALUES clause is not required with subquery.
The statement will fail because subquery in the VALUES clause is not enclosed with in single quotation marks.
View the Exhibit and examine the structure of the PRODUCTS, SALES, and SALE_SUMMARY tables. SALE_VW is a view created using the following command: SQL>CREATE VIEW sale_vw AS SELECT prod_id, SUM(quantity_sold) QTY_SOLD FROM sales GROUP BY prod_id; You issue the following command to add a row to the SALE_SUMMARY table: SQL>INSERT INTO sale_summary SELECT prod_id, prod_name, qty_sold FROM sale_vw JOIN products USING (prod_id) WHERE prod_id = 16; What is the outcome?
It executes successfully.
It gives an error because a complex view cannot be used to add data into the SALE_SUMMARY table.
It gives an error because the column names in the subquery and the SALE_SUMMARY table do not match.
It gives an error because the number of columns to be inserted does not match with the number of columns in the SALE_SUMMARY table.
View the Exhibit and examine the structure of CUSTOMERS and SALES tables.
Evaluate the following SQL statement: UPDATE (SELECT prod_id, cust_id, quantity_sold, time_id FROM sales) SET time_id = '22-MAR-2007' WHERE cust_id
= (SELECT cust_id FROM customers WHERE cust_last_name = 'Roberts' AND credit_limit = 600); Which statement is true regarding the execution of the above UPDATE statement?
It would not execute because two tables cannot be used in a single UPDATE statement.
It would not execute because the SELECT statement cannot be used in place of the table name.
It would execute and restrict modifications to only the columns specified in the SELECT statement.
It would not execute because a subquery cannot be used in the WHERE clause of an UPDATE statement.
One UPDATE statement can change rows in only one table, but it can change any number of rows in that table.
View the Exhibit and examine the structures of the EMPLOYEES and DEPARTMENTS tables. You want to update the EMPLOYEES table as follows:4 ? 4;
-Update only those employees who work in Boston or Seattle (locations 2900 and 2700).
-Set department_id for these employees to the department_id corresponding to London (location_id 2100).
-Set the employees' salary in location_id 2100 to 1.1 times the average salary of their department.
-Set the employees' commission in location_id 2100 to 1.5 times the average commission of their department.
You issue the following command: SQL>UPDATE employees SET department_id =
WHERE location_id = 2100), (salary, commission) =
(SELECT 1.1*AVG(salary), 1.5*AVG(commission) FROM employees, departments WHERE departments.location_id IN(2900,2700,2100)) WHERE department_id IN (SELECT department_id FROM departments WHERE location_id = 2900
OR location_id = 2700) What is the outcome?
It executes successfully and gives the correct result.
It executes successfully but does not give the correct result.
It generates an error because a subquery cannot have a join condition in an UPDATE statement.
It generates an error because multiple columns (SALARY, COMMISION) cannot be specified together in an UPDATE statement.
Which two statements are true regarding the DELETE and TRUNCATE commands? (Choose two.)
DELETE can be used to remove only rows from only one table at a time.
DELETE can be used to remove only rows from multiple tables at a time.
DELETE can be used only on a table that is a parent of a referential integrity constraint.
DELETE can be used to remove data from specific columns as well as complete rows.
DELETE and TRUNCATE can be used on a table that is a parent of a referential integrity constraint having ON DELETE rule.
Answer: A, E
Transactions, consisting of INSERT, UPDATE, and DELETE (or even MERGE) commands can be made permanent (with a COMMIT) or reversed (with a
ROLLBACK). A TRUNCATE command, like any other DDL command, is
immediately permanent: it can never be reversed. The Transaction Control Statements A transaction begins implicitly with the first DML statement. There is no command to explicitly start a transaction. The transaction continues through all subsequent DML statements issued by the session. These statements can be against any number of tables: a transaction is not restricted to one table. It terminates (barring any of the events listed in the previous section) when the session issues a COMMIT or ROLLBACK command. The SAVEPOINT command can be used to set markers that will stage the action of a ROLLBACK, but the same transaction remains in progress irrespective of the use of SAVEPOINT Explicit Transaction Control Statements You can control the logic of transactions by using the COMMIT, SAVEPOINT, and ROLLBACK statements. Note: You cannot COMMIT to a SAVEPOINT. SAVEPOINT is not ANSI-standard SQL.
Which statement is true regarding transactions? (Choose all that apply.)
A transaction can consist only of a set of DML and DDL statements.
A part or an entire transaction can be undone by using ROLLBACK command.
A transaction consists of a set of DML or DCL statements.
A part or an entire transaction can be made permanent with a COMMIT.
A transaction can consist of only a set of queries or DML or DDL statements.
Answer: B, C
Which two statements are true regarding savepoints? (Choose two.)
Savepoints are effective only for COMMIT.
Savepoints may be used to ROLLBACK.
Savepoints can be used for only DML statements.
Savepoints are effective for both COMMIT and ROLLBACK.
Savepoints can be used for both DML and DDL statements.
Answer: B, C
Read more Details »