Question: Create the following SQL code in the query window. Comment each step in the script.! Transaction 1 Prep Data as shown below DECLARE @NewStudentID int;
Create the following SQL code in the query window. Comment each step in the script.!
Transaction
Prep Data as shown below
DECLARE @NewStudentID int;
Set @NewStudentID ; initialized dummy value
DECLARE @CourseID int;
SET @CourseID ;
Write the next SQL statements as a transaction
INSERT Students VALUES Hamilton 'Alexander', GETDATE NULL;
SET @NewStudentID @@IDENTITY;
INSERT StudentCourses VALUES @NewStudentID, @CourseID;
If the previous step is successful, commit the transaction. Otherwise, issue a rollback.
Prior to the Commit Issue the command PRINT 'Commit of Student ID CAST@NewStudentID AS VARCHAR;
Prior to the Rollback Issue the command PRINT 'Rollback for Alexander Hamilton'
Outside of the transaction issue the command and inspect the results.
Select from Students order by EnrollmentDate;
Note: This transaction should show the "Commit" message.
Transaction
Copy all the Code from Transaction Make the following modifications to this copy.
Remove the copiedexisting INSERT Statement for Alexander Hamilton.
Add the following INSERT Statements in that place
INSERT Students VALUES Jackson 'Andrew', GETDATE NULL;
Issue the SET @NewStudentID and INSERT StudentCourses lines
INSERT Students VALUES Burr 'Aaron', GETDATE;
Issue the SET @NewStudentID and INSERT StudentCourses lines
If the previous step is successful, commit the transaction. Otherwise, issue a rollback.
Prior to the Commit Issue the command PRINT 'Commit of of Students'
Prior to the Rollback Issue the command PRINT 'Rollback for Students'
Outside of the transaction issue the command and inspect the results.
Select from Students order by EnrollmentDate;
Note this transaction should show ROLLBACK due to the invalid date in the Aaron Burr insert. Neither Burr or Andrew Jackson should be added
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
