Ifall någon som tittar på detta använder SQL Server 2008, var jag tvungen att göra ett par ändringar:
SELECT 'ALTER TABLE [' + sys.objects.name + '] ALTER COLUMN ['
+ sys.columns.name + '] ' + sys.types.name +
CASE sys.types.name
WHEN 'text' THEN ' '
ELSE
'(' + RTRIM(CASE sys.columns.max_length
WHEN -1 THEN 'MAX'
ELSE CONVERT(CHAR,sys.columns.max_length)
END) + ') '
END
+ ' ' + ' COLLATE Latin1_General_BIN ' + CASE sys.columns.is_nullable WHEN 0 THEN 'NOT NULL' ELSE 'NULL' END
FROM sys.columns , sys.objects , sys.types
WHERE sys.columns.object_id = sys.objects.object_id
AND sys.objects.TYPE = 'U'
AND sys.types.system_type_id = sys.columns.system_type_id
AND sys.columns.collation_name IS NOT NULL
AND NOT ( sys.objects.NAME LIKE 'sys%' )
AND NOT ( sys.types.name LIKE 'sys%' )