UPDATE mytable SET mycolumn= LTRIM(RTRIM(mycolumn));
works fine on trimming columns removing trailer spaces, but how can i adjust it to trim all column
If there are not too many columns, you could just
directly
UPDATE
each by your_column_name, via the TRIM()
function:
UPDATE mytable SET
mycolumn1 = TRIM(mycolumn1),
mycolumn2 = TRIM(mycolumn2),
mycolumn3 = TRIM(mycolumn3),
mycolumn4 = TRIM(mycolumn4)
Otherwise, ZweiStein's answer above for a single table,
or Izhar Aazmi's answer for an entire database seem the way to go.
Hiram's answer to another SO Post includes a check to only TRIM VARCHAR fields: excellent feature!
Or, if using T-SQL, or others which do not support TRIM
, use the LTRIM(RTRIM(...))
trick,
suggested by Jim Rubenstein and Denis de Bernardy above.