0% found this document useful (0 votes)
2K views3 pages

Machine Problem 1

The document provides SQL statements to demonstrate how to insert, update, delete, and rollback data in a MY_EMPLOYEES database table. It includes statements to: 1) Insert sample employee data into the table using different INSERT syntax; 2) Update specific employee records by changing names and salaries; 3) Delete a single employee record; 4) Use savepoints and rollbacks to control transactions and discard the most recent changes.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
2K views3 pages

Machine Problem 1

The document provides SQL statements to demonstrate how to insert, update, delete, and rollback data in a MY_EMPLOYEES database table. It includes statements to: 1) Insert sample employee data into the table using different INSERT syntax; 2) Update specific employee records by changing names and salaries; 3) Delete a single employee record; 4) Use savepoints and rollbacks to control transactions and discard the most recent changes.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 3

nMachine Problem 1: Manipulating Data http://www.scribd.

com/doc/51323039/Practice-Solutions Task The HR department wants you to create SQL statements to insert, update, and delete employee data. As a prototype, you use the MY_EMPLOYEES table before giving the statements to the HR department. Part 1 Insert data into MY_EMPLOYEES table. 1. Run the statement below to build the MY_EMPLOYEES table. CREATE TABLE my_employee (id NUMBER(4) CONSTRAINT my_employee_id_nn NOT NULL, last_name VARCHAR2(25), first_name VARCHAR2(25), userid VARCHAR2(8), salary NUMBER(9,2)); 2. Describe the structure of the MY_EMPLOYEES table to identify the column names. DESC my_employee; 3. Create an INSERT statement to add the first row of the data to the MY_EMPLOYEES table from the following sample data. Do not list the columns in the INSERT clause. Do not enter all rows yet.

INSERT INTO my_employee VALUES (1, 'Patel', 'Ralph', 'rpatel', 895);

4. Populate the MY_EMPLOYEE table with the second row of the sample data from the preceding list. This time, list the columns explicitly in the INSERT clause.

INSERT INTO my_employee (id, last_name, first_name,userid, salary) VALUES (2, 'Dancs', 'Betty', 'bdancs', 860);
5. Confirm your addition to the table.

SELECT *FROM my_employee;


6. Write an INSERT statement in a dynamic reusable script file to load the remaining rows into the MY_EMPLOYEES table. The script whould prompt for all columns (ID, LAST_NAME, FIRST_NAME, USERID, and SALARY). SET ECHO OFF SET VERIFY OFF INSERT INTO my_employee VALUES (&p_id, '&&p_last_name', '&&p_first_name',lower(substr('&p_first_name', 1, 1) ||substr('&p_last_name', 1, 7)), '&p_salary'); SET VERIFY ON SET ECHO ON

UNDEFINE p_first_name UNDEFINE p_last_name 7. Populate the table with the next two rows of the sample data listed in step 3 by running the INSERT statement in the script that you created in step 6. Same with 6 8. Confirm your additions to the table.

SELECT *FROM my_employee;


9. Make the data additions permanent.

COMMIT;
Part 2 Update and delete data in the MY_EMPLOYEES table. 10. Change the last name of employee 3 to Drexler. UPDATE my_employee SET last_name = 'Drexler' WHERE id = 3; 11. Change the salary to $1,000 for all employees who have a salary less than $900.

UPDATE my_employee SET salary = 1000 WHERE salary < 900;


12. Verify your changes to the table.

SELECT last_name, salary FROM my_employee;


13. Delete Betty Dancs from the MY_EMPLOYEES.

DELETE FROM my_employee WHERE last_name = 'Dancs';


14. Confirm your changes to the table.

SELECT *FROM my_employee;


15. Commit all pending changes.

COMMIT;
Part 3 Control data transaction to the MY_EMPLOYEE table. 16. Populate the table with the last row of the sample data listed in step 3 by using the statements in the script that you created in step 6. Run the statement in the script. 17. Confirm your addition to the table. SET ECHO OFF SET VERIFY OFF INSERT INTO my_employee VALUES (&p_id, '&&p_last_name', '&&p_first_name',lower(substr('&p_first_name', 1, 1) ||substr('&p_last_name', 1, 7)), '&p_salary'); SET VERIFY ON SET ECHO ON UNDEFINE p_first_name UNDEFINE p_last_name

18. Mark an intermediate point in the processing of the transaction.

SAVEPOINT step_18;
19. Delete all rows from the MY_EMPLOYEE table.

DELETE FROM my_employee;


20. Confirm that the table is empty.

SELECT *FROM my_employee;


21. Discard the most recent DELETE operation without discarding the earlier INSERT operation.

ROLLBACK TO step_18;
22. Confirm that the new row is still intact.

SELECT *FROM my_employee;


23. Make the data addition permanent.

COMMIT;
Note: The last output will be checked.

You might also like