Friday 3 February 2012

A Script A Day - Day 3 - Live Change Data Edit Template

Today's script is a template I use for the occasions when a data edit is required to be run against a live environment.  It has 8 steps to give you as DBA's control over what is being run and the safety of recording results before and after the modifications.  The comments section at the top is used to give you an instant view of who, what and where about the script.


/*
      -----------------------------------------------------------------
      Live Change Data Edit Script Template - Results to Text (Ctrl+T)
      -----------------------------------------------------------------
     
      Author:                                        
      Date:                              
      Code Reviewed By:            
      Test Environment:            
      Required Environment:        
      Description:                       
     
      -----------------------------------------------------------------

      For more SQL resources, check out SQLServer365.blogspot.co.uk

      -----------------------------------------------------------------

      You may alter this code for your own purposes.
      You may republish altered code as long as you give due credit.
      You must obtain prior permission before blogging this code.
 
      THIS CODE AND INFORMATION ARE PROVIDED "AS IS"
     
      -----------------------------------------------------------------
*/

-- Step 1
-- Set database context
USE ;
GO

-- Step 2
-- Run select statement(s) before data modifications for historical record


-- Step 3
-- Record results before data modifications
/*

*/

-- Step 4
-- Start of data modifications - Use BEGIN TRANSACTION to allow rollback if errors or unexpected results occur
PRINT '*** START DATA MODIFICATIONS ***'

BEGIN TRANSACTION

-- Step 5
-- End of data modifications
PRINT '*** END OF DATA MODIFICATIONS'

-- Step 6
-- COMMIT OR ROLLBACK? - FOR DBA USE WHEN BEING EXECUTED LEAVE COMMENTED OUT!

-- COMMIT TRANSACTION
-- ROLLBACK TRANSACTION

-- Step 7
-- Run select statement(s) after data modifications


-- Step 8
-- Record results after data modifications for historical record
/*

*/


Enjoy!


Chris

No comments:

Post a Comment