0% found this document useful (0 votes)
4 views5 pages

DBS211 Lab06 Transactions

This document outlines Lab 06 for DBS211, focusing on Transactions and Security in Database Systems. It includes objectives, tasks related to SQL commands for managing transactions, creating and manipulating tables, and setting permissions. The lab emphasizes the importance of executing tasks in a specific order for optimal learning and provides SQL examples for various operations.

Uploaded by

48ph4fpyhz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

DBS211 Lab06 Transactions

This document outlines Lab 06 for DBS211, focusing on Transactions and Security in Database Systems. It includes objectives, tasks related to SQL commands for managing transactions, creating and manipulating tables, and setting permissions. The lab emphasizes the importance of executing tasks in a specific order for optimal learning and provides SQL examples for various operations.

Uploaded by

48ph4fpyhz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

DBS211 – Introduction to Database Systems

Lab 06 – Transactions and Security


Objective:

Submission:
Your submission will be a .docx file with the solutions provided.

You will use following data to complete the given tasks:


employeeNumber lastname firstname extension email OfficeCode reportsTo jobTitle

100 Patel Ralph 22333 rpatel@mail.com 1 NULL Sales Rep


101 Denis Betty 33444 bdenis@mail.com 4 NULL Sales Rep
102 Biri Ben 44555 bbirir@mail.com 2 NULL Sales Rep
103 Newman Chad 66777 cnewman@mail.com 3 NULL Sales Rep
104 Ropeburn Audrey 77888 aropebur@mail.com 1 NULL Sales Rep

 SET TRANSACTION READ WRITE starts a new transaction.


 COMMIT commits the current transaction, making its changes permanent.
 SAVEPOINT <name> sets a pointer to a location that can be rolled back to.
 ROLLBACK rolls back the current transaction, canceling its changes.
 SET autocommit disables or enables the default autocommit mode for the current session.

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

i)making new connection from server


ii) using begin command
iii)using commit command
iv) using ddl commands

2. Using SQL, create an empty table, that is the same as the employees table, and name it
newEmployees.

CREATE TABLE newEmployees( employeeNumber NUMBER(3) PRIMARY KEY, lastname CHAR(12),


firstname CHAR(12),
extension NUMBER(6),
DBS211 – Introduction to Database Systems
email CHAR(30),
officeCode NUMBER(1),
reportsTo NUMBER(3) NULL,
jobtitle CHAR(12)
);

3. Execute the following commands.


SET AUTOCOMMIT OFF;
SET TRANSACTION READ WRITE;

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?

Select count (*) FROM newEmployees;

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.

UPDATE newEmployees SET jobtitle;

9. Make your changes permanent.

SELECT * FROM newEmployees;


COMMIT;
10. Execute the rollback command.

a. Display all employees from the newEmployees table whose job title is ‘unknown’. How many
rows are still updated?

SELECT * FROM newEmployees WHERE jobtitle= ‘unknown’;

b. Was the rollback command effective?

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

DELETE FROM newEmployees;

12. Create a VIEW, called vwNewEmps, that queries all the records in the newEmployees table sorted by
last name and then by first name.

CREATE VIEW vwEmps AS

SELECT * FROM newEmployees ORDER BY lastname,firstname;

13. Perform a rollback to undo the deletion of the employees


DBS211 – Introduction to Database Systems
a. How many employees are now in the newEmployees table?

b. Was the rollback effective and why?

14. Begin a new transaction and rerun the data insertion from Task 4 (copy the code down to Task 14 and
run it)

START TRANSACTION; /this isnt working/

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 (103, 'Newman', 'Chad', 66777, 'cnewman@mail.com', 3,


NULL, 'Sales Rep');

INSERT INTO newEmployees VALUES (104, 'Ropeburn', 'Audrey', 77888, 'aropebur@mail.com', 1, NULL,
'Sales Rep');

15. Set a Savepoint, called insertion, after inserting the data

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

SET jobTitle = 'Unknown';

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;

select * from vwNewEmps;


DBS211 – Introduction to Database Systems
Part B - Permissions
19. Write a statement that denies all access to the newemployees table for all public users

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.

DENY DELETE,INSERT,REFERENCES,SELECT,UPDATE ON “dbs211_211”.”NEWEMPLOYEES” TO dbs211_

Part C – Clean up
23. Write statements to permanently remove the view and table created for this lab

DROP TABLE newEmployees;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy