SQL Server UPPERCASE for all data for all columns in the table

后端 未结 2 1469
忘了有多久
忘了有多久 2021-01-24 13:58

I would like to know how to convert all data to UPPERCASE for all columns name and the values in them for a table. The data may contain int but it will ignore it. S

2条回答
  •  佛祖请我去吃肉
    2021-01-24 14:51

    Dynamic SQL is probably your only option. Something like this should would using FOR XML querying INFORMATION_SCHEMA.COLUMNS:

    declare @query varchar(max)
    set @query = ''
    
    select @query =
      STUFF((
        select ';UPDATE ' + table_name + ' SET ' + column_name + ' = UPPER(' + column_name + ')'
        from INFORMATION_SCHEMA.COLUMNS
        order by table_name, column_name
        for xml path('')
            ), 1, 1, '')
    
    execute(@query);
    

    SQL Fiddle Demo

提交回复
热议问题