A simple script to decapitalize Column names

The below script can take column names for all tables in the database and provide the rename script to only capitalize the first letter.

SELECT 'exec sp_rename ' + CHAR(39) + TABLE_NAME + '.' + COLUMN_NAME + CHAR(39) + ',' + CHAR(39) + REPLACE(COLUMN_NAME, RIGHT(COLUMN_NAME, LEN(COLUMN_NAME) - 1), LOWER(RIGHT(COLUMN_NAME, LEN(COLUMN_NAME) - 1))) + CHAR(39) + ', ''COLUMN'''
FROM INFORMATION_SCHEMA.COLUMNS

Sometimes we just want our code to look pretty.

Leave a Reply