SlideShare a Scribd company logo
1 of 4
Unit 13 – Your Answers
Ted Carr (S00942627)
IT 2351 – Enterprise Database Systems
06 November 2016
Your Answers
1 Transaction with ROLLBACK
Text of your CREATE PROCEDURE
-- 13.1 Ted Carr (S00942627)
-- Demonstrate transaction failure with ROLLBACK
USE college;
DROP procedure IF EXISTS Fix_Egghead1;
DELIMITER //
CREATE PROCEDURE Fix_Egghead1()
BEGIN
DECLARE sql_error TINYINT DEFAULT FALSE;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
SET sql_error = TRUE;
START TRANSACTION;
DELETE FROM student
WHERE student.ID = 27;
INSERT INTO faculty
VALUES (DEFAULT, 'Egghead', 'Eduardo', 'EduardoEgghead@college.edu', CURDATE(), 105000, 1);
IF sql_error = FALSE THEN
Page 1 of 4
Unit 13 – Your Answers
COMMIT;
SELECT 'The transaction was committed.’
ELSE
ROLLBACK;
SELECT 'The transaction was rolled back.’
END IF;
END //
DELIMITER ;
CALL Fix_Egghead1();
Screen shot of the result grid from stored procedure
Transaction with COMMIT
Page 2 of 4
Unit 13 – Your Answers
2 Text of your CREATE PROCEDURE
-- 13.2 Ted Carr (S00942627)
-- Demonstrate transaction success with ROLLBACK
USE college;
DROP procedure IF EXISTS Fix_Egghead1;
DELIMITER //
CREATE PROCEDURE Fix_Egghead1()
BEGIN
DECLARE sql_error TINYINT DEFAULT FALSE;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
SET sql_error = TRUE;
START TRANSACTION;
DELETE FROM registration
WHERE registration.StudentID = 27;
DELETE FROM student
WHERE student.ID = 27;
INSERT INTO faculty
VALUES (DEFAULT, 'Egghead', 'Eduardo', 'EduardoEgghead@college.edu', CURDATE(), 105000, 1);
IF sql_error = FALSE THEN
COMMIT;
Page 3 of 4
Unit 13 – Your Answers
SELECT 'The transaction was committed.’
ELSE
ROLLBACK;
SELECT 'The transaction was rolled back.’
END IF;
END //
DELIMITER ;
CALL Fix_Egghead1();
Screen shot of the result grid from stored procedure
Page 4 of 4

More Related Content

Viewers also liked

Viewers also liked (10)

MBA certificate
MBA certificateMBA certificate
MBA certificate
 
Plan de accion diapositivas
Plan de accion diapositivasPlan de accion diapositivas
Plan de accion diapositivas
 
Halloween completo
Halloween completoHalloween completo
Halloween completo
 
web
webweb
web
 
Asado de puerco
Asado de puercoAsado de puerco
Asado de puerco
 
Eli Young Band
Eli Young BandEli Young Band
Eli Young Band
 
Organizadores graficos segundo,tercero y cuarto bloque
Organizadores graficos segundo,tercero y cuarto bloqueOrganizadores graficos segundo,tercero y cuarto bloque
Organizadores graficos segundo,tercero y cuarto bloque
 
Biología 3° Medio
Biología 3° MedioBiología 3° Medio
Biología 3° Medio
 
Presentación1
Presentación1Presentación1
Presentación1
 
Precentacion de etica y valores 2do bloque
Precentacion de etica y valores 2do bloquePrecentacion de etica y valores 2do bloque
Precentacion de etica y valores 2do bloque
 

Unit13Answers - Ted Carr

  • 1. Unit 13 – Your Answers Ted Carr (S00942627) IT 2351 – Enterprise Database Systems 06 November 2016 Your Answers 1 Transaction with ROLLBACK Text of your CREATE PROCEDURE -- 13.1 Ted Carr (S00942627) -- Demonstrate transaction failure with ROLLBACK USE college; DROP procedure IF EXISTS Fix_Egghead1; DELIMITER // CREATE PROCEDURE Fix_Egghead1() BEGIN DECLARE sql_error TINYINT DEFAULT FALSE; DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET sql_error = TRUE; START TRANSACTION; DELETE FROM student WHERE student.ID = 27; INSERT INTO faculty VALUES (DEFAULT, 'Egghead', 'Eduardo', 'EduardoEgghead@college.edu', CURDATE(), 105000, 1); IF sql_error = FALSE THEN Page 1 of 4
  • 2. Unit 13 – Your Answers COMMIT; SELECT 'The transaction was committed.’ ELSE ROLLBACK; SELECT 'The transaction was rolled back.’ END IF; END // DELIMITER ; CALL Fix_Egghead1(); Screen shot of the result grid from stored procedure Transaction with COMMIT Page 2 of 4
  • 3. Unit 13 – Your Answers 2 Text of your CREATE PROCEDURE -- 13.2 Ted Carr (S00942627) -- Demonstrate transaction success with ROLLBACK USE college; DROP procedure IF EXISTS Fix_Egghead1; DELIMITER // CREATE PROCEDURE Fix_Egghead1() BEGIN DECLARE sql_error TINYINT DEFAULT FALSE; DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET sql_error = TRUE; START TRANSACTION; DELETE FROM registration WHERE registration.StudentID = 27; DELETE FROM student WHERE student.ID = 27; INSERT INTO faculty VALUES (DEFAULT, 'Egghead', 'Eduardo', 'EduardoEgghead@college.edu', CURDATE(), 105000, 1); IF sql_error = FALSE THEN COMMIT; Page 3 of 4
  • 4. Unit 13 – Your Answers SELECT 'The transaction was committed.’ ELSE ROLLBACK; SELECT 'The transaction was rolled back.’ END IF; END // DELIMITER ; CALL Fix_Egghead1(); Screen shot of the result grid from stored procedure Page 4 of 4