Can I globally convert all text in the databases to UPPER CASE. This is only test data but lots of it 20,000,000 rows 145 columns that are( 'char', 'nchar', 'varchar', 'nvarchar')
Does anyone have ideas on how to do this...? I know you can use UPPER
Update table
set col1 = UPPER(col1)
But this limits it to an individual c开发者_StackOverflowolumn But how do I create a cursor using the information schema views and loop through all the character type columns to determine which to update:
select table_name, column_name from information_schema.columns
where data_type in ('char', 'nchar', 'varchar', 'nvarchar')
I have no FKs in the tables Thanks
if its a hacky one-off just make the query spit out some copy/pasteable SQL;
SELECT 'update [' + p1.table_name + '] set ' +
(SELECT
CASE WHEN ROW_NUMBER() OVER (order by column_name) > 1 THEN ',' ELSE '' END
+ '[' + column_name + ']=upper([' + column_name + '])'
FROM information_schema.columns p2
WHERE p2.table_name = p1.table_name and p2.data_type in ('char', 'nchar', 'varchar', 'nvarchar')
ORDER BY table_name
FOR XML PATH('')
) AS blah
FROM information_schema.columns p1
WHERE p1.data_type in ('char', 'nchar', 'varchar', 'nvarchar')
GROUP BY table_name;
which would spit out;
update [Tbl] set [F1]=upper([F1]),[F2]=upper([F2])
精彩评论