DECLARE @tableName NVARCHAR(256),
		@oldColumnName NVARCHAR(256),
		@newValue NVARCHAR(256),
		@columnName NVARCHAR(256);

-- rename tables
SELECT @tableName = (select TOP 1 name from sys.objects where type = 'U' and schema_id = SCHEMA_ID() and HASHBYTES('sha1', name) != HASHBYTES('sha1', UPPER(name)))
WHILE @tableName IS NOT NULL
BEGIN
	PRINT CONCAT('Rename ', @tableName)

	SET @newValue = UPPER(@tableName);

	EXEC sp_rename @tableName, @newValue;

	SELECT @tableName = (select TOP 1 name from sys.objects where type = 'U' and schema_id = SCHEMA_ID() and HASHBYTES('sha1', name) != HASHBYTES('sha1', UPPER(name)))
END

-- rename columns
select TOP 1 @tablename = o.name, @columnName = c.name from sys.objects o JOIN sys.columns c ON (o.object_id = c.object_id) where o.type = 'U' and o.is_ms_shipped = 0 and o.schema_id = SCHEMA_ID() and HASHBYTES('sha1', c.name) != HASHBYTES('sha1', UPPER(c.name))
WHILE @columnName IS NOT NULL
BEGIN
	PRINT CONCAT('Rename Column ', @columnName, ' of table ', @tableName)

	SET @newValue = UPPER(@columnName)
	SET @oldColumnName = CONCAT(@tableName, '.', @columnName)

	EXEC sp_rename @oldColumnName, @newValue, 'COLUMN';

	SET @tableName = NULL
	SET @columnName = NULL

	select TOP 1 @tablename = o.name, @columnName = c.name from sys.objects o JOIN sys.columns c ON (o.object_id = c.object_id) where o.type = 'U' and o.is_ms_shipped = 0 and o.schema_id = SCHEMA_ID() and HASHBYTES('sha1', c.name) != HASHBYTES('sha1', UPPER(c.name))
END
