Skip to content

Instantly share code, notes, and snippets.

@BrianMRO
Created February 4, 2021 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrianMRO/7c6efe74d9ce372ba30d04dd87128b48 to your computer and use it in GitHub Desktop.
Save BrianMRO/7c6efe74d9ce372ba30d04dd87128b48 to your computer and use it in GitHub Desktop.
Refactor OwnerID - Step 1
USE [MyDatabase]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF COL_LENGTH('dbo.XXMyTable', 'OldOwnerID') IS NULL
BEGIN
EXEC sp_rename 'XXMyTable.OwnerID', 'OldOwnerID', 'COLUMN';
ALTER TABLE XXMyTable ADD OwnerID INT NULL;
END
IF COL_LENGTH('dbo.XXMyTable', 'OldProductManagerID') IS NULL
BEGIN
EXEC sp_rename 'XXMyTable.ProductManagerID', 'OldProductManagerID', 'COLUMN';
ALTER TABLE XXMyTable ADD ProductManagerID INT NULL;
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment