Machine Problem 1
Machine Problem 1
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.
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.
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.
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.
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
SAVEPOINT step_18;
19. Delete all rows from the MY_EMPLOYEE table.
ROLLBACK TO step_18;
22. Confirm that the new row is still intact.
COMMIT;
Note: The last output will be checked.