a) Q4. Views Provide an example of a view that is not updatable. Briefly explain why....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
a) Q4. Views Provide an example of a view that is not updatable. Briefly explain why. b) Assuming the following view has been created. How would you modify the existing view to remove the column first? You can provide a query or describe what you plan to do. CREATE VIEW HISTMAJ (last, first, stuID) AS SELECT lastName, firstName, stuID FROM Student WHERE major='History'; Q5. Permissions Suppose the following command is issued: GRANT SELECT ON Student TO U1, U2, U3 WITH GRANT OPTION; Complete the answer below assuming the order of the commands in which they are presented to you. a) Can U3 issue the following command? Why or why not? (5 pts) GRANT SELECT ON Student TO U4 WITH GRANT OPTION; b) Can U4 issue the following command? Why or why not? (5 pts) GRANT SELECT ON Student TO U5; c) A DBA issued the following command REVOKE SELECT ON Student FROM U3; WEES Can U4 issue the following command? Why or why not? (5 pts) GRANT SELECT ON Student TO U6 WITH GRANT OPTION; Assume that the code below works. Answer the following questions. DECLARE v_emp_id NUMBER := 101; v_salary NUMBER; v_bonus NUMBER := 500; BEGIN SAVEPOINT start_transaction; Q6. Transaction Management SELECT salary INTO v_salary FROM employees WHERE employee_id = v_emp_id; v_salary := v_salary + v_bonus; UPDATE employees SET salary = v_salary WHERE employee_id = v_emp_id; DBMS_OUTPUT.PUT_LINE('New salary for employee ' || v_emp_id || ': ' || v_salary); SAVEPOINT after_update; -- Simulate an error condition -- RAISE_APPLICATION ERROR(-20001, 'Simulation of an error during transaction.'); 11 If no error occurs, commit the changes COMMIT; EXCEPTION WHEN OTHERS THEN ROLLBACK TO SAVEPOINT start_transaction; DBMS_OUTPUT.PUT_LINE('Error:' || SQLCODE ||-' || SQLERRM); END; 1 (1) Explain the purpose and functionality of the SAVEPOINT statements in the provided code. Discuss how the use of savepoints contributes to the management of transactions and error handling. (2) Explain how the code would behave in the following scenarios: a) When no error occurs during the execution of the code. b) When an error occurs during the execution of the code. You are given the following code: create or replace trigger MAINTAIN_TOTAL after insert or delete or update of PRICE, QUANTITY on S ITEM Q7. Triggers, Exceptions, Constraints for each row begin if deleting then INCREMENT TOTAL (:OLD. ORD_ID, -1 * nvl (:OLD. PRICE, 0) * nvl (:OLD.QUANTITY, 0)); INCREMENT TOTAL (:NEW.ORD ID, nvl (: NEW.PRICE, 0) * nvl (:NEW.QUANTITY,0) - nvl (:OLD. PRICE, 0) * nvl (:OLD. QUANTITY, 0)); elsif updating then else /* inserting */ INCREMENT_TOTAL (: NEW.ORD_ID, end if; end; nvl (:NEW. PRICE, 0) * nvl (:NEW.QUANTITY, 0)); Will the commands below fire the trigger above? For each of the questions, please suggest what the output will be and briefly explain. a) UPDATE S_ITEM SET RATING = 4; b) INSERT INTO S_ITEM values('anna001', 41, 'cnit372'); c) INSERT INTO S_ITEM values('anna002', 140, 'cs101'); d) UPDATE S_ITEM SET QUANTITY = 2; e) DELETE FROM S_ITEM; Q3. Packages You do not need to trace the code for the following questions, just look at where and how the procedures and functions are defined. Assume that the code for the package below works: CREATE OR REPLACE PACKAGE emp_admin AS Declare externally visible types, cursor, exception TYPE EmpRecTyp IS RECORD (emp_id NUMBER, sal NUMBER); CURSOR desc_salary RETURN EmpRecTyp; invalid_salary EXCEPTION; RETURN NUMBER; PROCEDURE fire_employee (emp_id NUMBER); PROCEDURE fire_employee (emp_email VARCHAR2); PROCEDURE raise_salary (emp_id NUMBER, amount NUMBER); FUNCTION nth_highest_salary (n NUMBER) RETURN EmpRecTyp; END emp_admin; Declare externally callable subprograms FUNCTION hire_employee (last_name VARCHAR2, first_name VARCHAR2, email VARCHAR2, phone_number VARCHAR2, job_id VARCHAR2, salary NUMBER, commission_pct NUMBER, manager_id NUMBER, department_id NUMBER) - 1 (The following screenshots all describe the package body definition) CREATE OR REPLACE PACKAGE BODY emp_admin AS number_hired NUMBER; visible only in this package Fully define cursor specified in package CURSOR desc_salary RETURN EmpRecTyp IS SELECT employee_id, salary FROM employees ORDER BY salary DESC; Fully define subprograms specified in package FUNCTION hire_employee (last_name VARCHAR2, first_name VARCHAR2, email VARCHAR2, phone_number VARCHAR2, job_id VARCHAR2, salary NUMBER, commission_pct NUMBER, manager_id NUMBER, department_id NUMBER) RETURN NUMBER IS new_emp_id NUMBER; BEGIN -- overloaded subprogram 11 RETURN new_emp_id; overloaded subprogram END hire_employee; SELECT employees_seq.NEXTVAL INTO new_emp_id FROM dual; INSERT INTO employees VALUES (new_emp_id, last_name, first_name, email, phone_number, SYSDATE, job_id, salary, commission_pct, manager_id, department_id); number_hired := number_hired + 1; DBMS_OUTPUT.PUT_LINE('The number of employees hired is ' || TO_CHAR (number_hired) ); a) Q4. Views Provide an example of a view that is not updatable. Briefly explain why. b) Assuming the following view has been created. How would you modify the existing view to remove the column first? You can provide a query or describe what you plan to do. CREATE VIEW HISTMAJ (last, first, stuID) AS SELECT lastName, firstName, stuID FROM Student WHERE major='History'; Q5. Permissions Suppose the following command is issued: GRANT SELECT ON Student TO U1, U2, U3 WITH GRANT OPTION; Complete the answer below assuming the order of the commands in which they are presented to you. a) Can U3 issue the following command? Why or why not? (5 pts) GRANT SELECT ON Student TO U4 WITH GRANT OPTION; b) Can U4 issue the following command? Why or why not? (5 pts) GRANT SELECT ON Student TO U5; c) A DBA issued the following command REVOKE SELECT ON Student FROM U3; WEES Can U4 issue the following command? Why or why not? (5 pts) GRANT SELECT ON Student TO U6 WITH GRANT OPTION; Assume that the code below works. Answer the following questions. DECLARE v_emp_id NUMBER := 101; v_salary NUMBER; v_bonus NUMBER := 500; BEGIN SAVEPOINT start_transaction; Q6. Transaction Management SELECT salary INTO v_salary FROM employees WHERE employee_id = v_emp_id; v_salary := v_salary + v_bonus; UPDATE employees SET salary = v_salary WHERE employee_id = v_emp_id; DBMS_OUTPUT.PUT_LINE('New salary for employee ' || v_emp_id || ': ' || v_salary); SAVEPOINT after_update; -- Simulate an error condition -- RAISE_APPLICATION ERROR(-20001, 'Simulation of an error during transaction.'); 11 If no error occurs, commit the changes COMMIT; EXCEPTION WHEN OTHERS THEN ROLLBACK TO SAVEPOINT start_transaction; DBMS_OUTPUT.PUT_LINE('Error:' || SQLCODE ||-' || SQLERRM); END; 1 (1) Explain the purpose and functionality of the SAVEPOINT statements in the provided code. Discuss how the use of savepoints contributes to the management of transactions and error handling. (2) Explain how the code would behave in the following scenarios: a) When no error occurs during the execution of the code. b) When an error occurs during the execution of the code. You are given the following code: create or replace trigger MAINTAIN_TOTAL after insert or delete or update of PRICE, QUANTITY on S ITEM Q7. Triggers, Exceptions, Constraints for each row begin if deleting then INCREMENT TOTAL (:OLD. ORD_ID, -1 * nvl (:OLD. PRICE, 0) * nvl (:OLD.QUANTITY, 0)); INCREMENT TOTAL (:NEW.ORD ID, nvl (: NEW.PRICE, 0) * nvl (:NEW.QUANTITY,0) - nvl (:OLD. PRICE, 0) * nvl (:OLD. QUANTITY, 0)); elsif updating then else /* inserting */ INCREMENT_TOTAL (: NEW.ORD_ID, end if; end; nvl (:NEW. PRICE, 0) * nvl (:NEW.QUANTITY, 0)); Will the commands below fire the trigger above? For each of the questions, please suggest what the output will be and briefly explain. a) UPDATE S_ITEM SET RATING = 4; b) INSERT INTO S_ITEM values('anna001', 41, 'cnit372'); c) INSERT INTO S_ITEM values('anna002', 140, 'cs101'); d) UPDATE S_ITEM SET QUANTITY = 2; e) DELETE FROM S_ITEM; Q3. Packages You do not need to trace the code for the following questions, just look at where and how the procedures and functions are defined. Assume that the code for the package below works: CREATE OR REPLACE PACKAGE emp_admin AS Declare externally visible types, cursor, exception TYPE EmpRecTyp IS RECORD (emp_id NUMBER, sal NUMBER); CURSOR desc_salary RETURN EmpRecTyp; invalid_salary EXCEPTION; RETURN NUMBER; PROCEDURE fire_employee (emp_id NUMBER); PROCEDURE fire_employee (emp_email VARCHAR2); PROCEDURE raise_salary (emp_id NUMBER, amount NUMBER); FUNCTION nth_highest_salary (n NUMBER) RETURN EmpRecTyp; END emp_admin; Declare externally callable subprograms FUNCTION hire_employee (last_name VARCHAR2, first_name VARCHAR2, email VARCHAR2, phone_number VARCHAR2, job_id VARCHAR2, salary NUMBER, commission_pct NUMBER, manager_id NUMBER, department_id NUMBER) - 1 (The following screenshots all describe the package body definition) CREATE OR REPLACE PACKAGE BODY emp_admin AS number_hired NUMBER; visible only in this package Fully define cursor specified in package CURSOR desc_salary RETURN EmpRecTyp IS SELECT employee_id, salary FROM employees ORDER BY salary DESC; Fully define subprograms specified in package FUNCTION hire_employee (last_name VARCHAR2, first_name VARCHAR2, email VARCHAR2, phone_number VARCHAR2, job_id VARCHAR2, salary NUMBER, commission_pct NUMBER, manager_id NUMBER, department_id NUMBER) RETURN NUMBER IS new_emp_id NUMBER; BEGIN -- overloaded subprogram 11 RETURN new_emp_id; overloaded subprogram END hire_employee; SELECT employees_seq.NEXTVAL INTO new_emp_id FROM dual; INSERT INTO employees VALUES (new_emp_id, last_name, first_name, email, phone_number, SYSDATE, job_id, salary, commission_pct, manager_id, department_id); number_hired := number_hired + 1; DBMS_OUTPUT.PUT_LINE('The number of employees hired is ' || TO_CHAR (number_hired) );
Expert Answer:
Related Book For
Database management systems
ISBN: 978-0072465631
3rd edition
Authors: Raghu Ramakrishan, Johannes Gehrke, Scott Selikoff
Posted Date:
Students also viewed these databases questions
-
answer all questions as instructed below. make sure you have attended all questions .Comparative Architectures (a) Describe the organisation of a two-level branch predictor that makes use of a global...
-
For continuous random variables X and Y , taking on continuous values x and y respectively with probability densities p(x) and p(y) and with joint probability distribution p(x, y) and conditional...
-
Which of the following variables was controlled in Experiment 1? F. Amount of yeast G. Percent of molasses H. Percent of sucrose J. Carbon dioxide levels Experiment 1 Since yeast needs sucrose to...
-
A box containing 500 smart phones has 20 defective phones. If 10 phones are selected together from the box, what is the probability that (a) All 10 are defective? (b) None is defective? (c) Half of...
-
Show that the sum HA of the moments about a point A of the moment of the particles of a rigid slab in plane motion is equal to IA , where is the angular velocity of the slab at the instant...
-
Reconstruct the half-normal plot shown in Figure 6.8 using geom_qq() and geom_qq_line(). Data from Figure 6.8 Factorial Effects B:C -2 B -1.5 -1.0 -0.5 0.0 A:B AB.C 2.0- A A:C B Absolute Factorial...
-
Grizzly Community Hospital in central Wyoming provides health care services to families living within a 200-mile radius. The hospital is extremely well equipped for a relatively small, community...
-
The letters of the word HAT are cut apart and put into a bag. One letter is drawn from the bag and a standard die is rolled. What is the probability of drawing the letter A and rolling a number that...
-
A company wants to build a website where user can register themselves and buy/renew health insurance policies. Also, they can process claims from a separate section on the website. Once logged in,...
-
9-32 An investor is considering buying some land for $100,000 and constructing an office building on it. Three different buildings are being analyzed. Building Height 2 Stories 5 Stories 10 Stories...
-
Kaylin Marcotte was putting in long hours at the Skimm, a media startup, and needed a way to unwind. She was on screens all day and wanted to do something with her hands. She hit upon puzzles and...
-
A material is required for a heat exchanger for cooling a small marine engine, saline, water at \(120^{\circ} \mathrm{C}\) (and thus under pressure). List function and constraints, set the objective...
-
Consider a flat plate mounted in the test section of a supersonic wind tunnel. The plate is at an angle of attack of \(10^{\circ}\) and the static pressure on the top surface of the plate is \(1.0...
-
A material is required to manufacture office scissors. Paper is an abrasive material, and scissors sometimes encounter hard obstacles like staples. List function and constraints, set the objective to...
-
Formulate the constraints and objective you would associate with the choice of material to make the forks of a racing bicycle.
-
1. A one year note with a face value of $20,000 is discounted 10 % and is sold to a third party. The note pays 5 percent interest per year. What is the third partys rate of return? 2. What is the net...
-
Evaluate how many lines there are in a true rotational spectrum of CO molecules whose natural vibration frequency is w = 4.09 1014 s1 and moment of inertia I = 1.44 1039 g cm2.
-
In answering the following questions, assume that the full deletion algorithm is used. Assume that merging is done when a bucket becomes empty. 1. Give an example of Extendible Hashing where deleting...
-
Answer the following questions: 1. What is the minimum space utilization for a B+ tree index? 2. What is the minimum space utilization for an ISAM index? 3. If your database system supported both a...
-
Briefly answer the following questions: 1. Explain the following terms and describe what they are used for: HTML, URL, XML, Java, JSP, XSL, XSLT, servlet, cookie, HTTP, CSS, DTD. 2. What is CGI? Why...
-
Consider a two-level system, with basis \(|1angle,|2angle\), and in this basis, a Hamiltonian with elements \(\left(\begin{array}{ll}1 & 1 \\ 1 & 1\end{array} ight)\). Use the first form of the...
-
Use the practical variational method for the same harmonic oscillator ground state energy, with trial wave function \(\psi_{a}(x)=e^{-a y^{2}}\).
-
Use the Ritz variational method for the harmonic oscillator, with trial wave functions \(\psi_{1}(x)=\) \(e^{-y^{2} / 2}, \psi_{2}(x)=e^{-y^{2}}, \psi_{3}(x)=e^{-2 y^{2}}\), where \(y=x \sqrt{m...
Study smarter with the SolutionInn App