DBS211 Lab06 Transactions
DBS211 Lab06 Transactions
Submission:
Your submission will be a .docx file with the solutions provided.
Tasks:
It is very important that these tasks be performed in the order presented here for maximum learning.
PART A - Transactions
1. List the 4 ways that we know that a transaction can be started
2. Using SQL, create an empty table, that is the same as the employees table, and name it
newEmployees.
4. Write an INSERT statement to populate the newEmployees table with the rows of the sample data.
Insert the NULL value for the reportsTo column. (Write a single INSERT statement to insert all the rows)
INSERT ALL
INTO newEmployees
VALUES(100,'Patel','Ralph',22333,'rpatel@mail.com',1,NULL,'Sales Rep') INTO newEmployees
VALUES(101,'Denis','Betty',33444,'bdenis@mail.com',4,NULL,'Sales Rep') INTO newEmployees
VALUES(102,'Biri','Ben',44555,'bbirir@mail.com',2,NULL,'Sales Rep') INTO newEmployees
VALUES(103,'Newman','Chad',66777,'cnewman@mail.com',3,NULL,'Sales Rep')
INTO newEmployees VALUES(104,'Ropeburn','Audrey',77888,'aropebur@mail.com',1,NULL,'Sales Rep')
SELECT * FROM DUAL;
COMMIT;
5. Create a query that shows all the inserted rows from the newEmployees table. How many rows are
selected?
6. Execute the rollback command. Display all rows and columns from the newEmployees table. How many
rows are selected?
ROLLBACK;
SELECT COUNT(*) FROM newEmployees;
7. Repeat Task 4. Make the insertion permanent to the table newEmployees. Display all rows and
columns from the newEmployee table. How many rows are selected?
INSERT ALL
INTO newEmployees
VALUES(100,'Patel','Ralph',22333,'rpatel@mail.com',1,NULL,'Sales Rep') INTO newEmployees
VALUES(101,'Denis','Betty',33444,'bdenis@mail.com',4,NULL,'Sales Rep') INTO newEmployees
VALUES(102,'Biri','Ben',44555,'bbirir@mail.com',2,NULL,'Sales Rep') INTO newEmployees
DBS211 – Introduction to Database Systems
VALUES(103,'Newman','Chad',66777,'cnewman@mail.com',3,NULL,'Sales Rep')
INTO newEmployees VALUES(104,'Ropeburn','Audrey',77888,'aropebur@mail.com',1,NULL,'Sales Rep')
SELECT * FROM DUAL;
COMMIT;
8. Write an update statement to update the value of column jobTitle to ‘unknown’ for all the employees
in the newEmployees table.
a. Display all employees from the newEmployees table whose job title is ‘unknown’. How many
rows are still updated?
ROLLBACK command is not effective because the change we did was permanent using commit
command
c. What was the difference between the result of the rollback execution from Task 6 and the
result of the rollback execution of this task?
COMMIT
11. Begin a new transaction and then create a statement to delete all employees from the newEmployees
table
12. Create a VIEW, called vwNewEmps, that queries all the records in the newEmployees table sorted by
last name and then by first name.
14. Begin a new transaction and rerun the data insertion from Task 4 (copy the code down to Task 14 and
run it)
INSERT INTO newEmployees VALUES (100, 'Patel', 'Ralph', 22333, 'rpatel@mail.com', 1, NULL, 'Sales
Rep');
iNSERT INTO newEmployees VALUES (101, 'Denis', 'Betty', 33444, 'bdenis@mail.com', 4, NULL, 'Sales
Rep');
INSERT INTO newEmployees VALUES (102, 'Biri', 'Ben', 44555, 'bbirir@mail.com', 2, NULL,'Sales
Rep');
INSERT INTO newEmployees VALUES (104, 'Ropeburn', 'Audrey', 77888, 'aropebur@mail.com', 1, NULL,
'Sales Rep');
Savepoint INSERTION;
16. Rerun the update statement from Task 8 and run a query to view the data (copy the code down and
run it again)
UPDATE newEmployees
17. Rollback the transaction to the Savepoint created in task 15 above and run a query to view the data.
What does the data look like (i.e. describe what happened?
18. Use the basic form of the rollback statement and again view the data. Describe what the results look
like and what happened.
rollback;
20. Write a statement that allows a classmate (use their database login) read only access to the
newemployees table.
21. Write a statement that allows the same classmate to modify (insert, update and delete) the data of the
newemployees table.
22. Write a statement the denies all access to the newemployees table for the same classmate.
Part C – Clean up
23. Write statements to permanently remove the view and table created for this lab