Last active
January 19, 2016 07:38
-
-
Save DylanKnevitt/fd603fb68bf2216613bc to your computer and use it in GitHub Desktop.
I needed to convert a float type to decimal. I then thought, why not change them all! This generates the scripts that need to be run in order to do so.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Find Type Here | |
--SELECT * FROM sys.Types | |
DECLARE @CurrentTypeName NVARCHAR(50) = 'float' | |
DECLARE @NewTypeName NVARCHAR(50) = 'decimal' | |
DECLARE @Nullable VARCHAR(8) = 'NOT NULL' | |
--Type specific Variables | |
DECLARE @DecimalPrecisionAndScale NVARCHAR(10) = '(18,2)' | |
SELECT 'ALTER TABLE ' + st.name + ' ALTER COLUMN ' + sc.name + ' ' + @NewTypeName + @DecimalPrecisionAndScale + ' ' + @Nullable FROM sys.tables st | |
INNER JOIN sys.columns sc on sc.object_id = st.object_id | |
INNER JOIN sys.types ct on ct.system_type_id = sc.system_type_id | |
WHERE ct.name = @CurrentTypeName | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment