Trim all database fields

后端 未结 9 1944
孤城傲影
孤城傲影 2020-12-29 15:05

Do you know if there\'s a quick way in sql server (via transact-sql) that I could trim all the database string fields.

9条回答
  •  萌比男神i
    2020-12-29 15:11

    Updated the answer of dan to use all tables in the database. Just run the snippet and copy the result to execute.

    SELECT 'UPDATE [' + TABLE_SCHEMA + '].[' + TABLE_NAME + '] SET [' + Column_Name + '] = ' + 'LTRIM(RTRIM([' + Column_Name + ']))' 
    FROM INFORMATION_SCHEMA.Columns c
    WHERE Data_Type LIKE '%CHAR%'
    

提交回复
热议问题