MS-SQL capitalize all table names

DECLARE @TableName NVARCHAR(500)
DECLARE @NewTableName sysname
DECLARE A CURSOR FOR SELECT [name] FROM sys.objects o WHERE o.[type] = ‘U’
OPEN A
FETCH NEXT FROM A INTO @TableName
WHILE(@@FETCH_STATUS=0)
BEGIN
  SET @NewTableName = UPPER(@TableName)
  IF @TableName COLLATE SQL_Latin1_General_CP1_CS_AS <> @NewTableName COLLATE SQL_Latin1_General_CP1_CS_AS
  BEGIN
    EXEC sp_rename @TableName, @NewTableName, ‘object’
  END
  FETCH NEXT FROM A INTO @TableName
END
CLOSE A
DEALLOCATE A
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s