Remove White Spaces or Special Characters from Database

The best way to remove all spaces from a string in SQL Server. So you want to remove trailing white spaces or leading white spaces or special characters from either MySQL or MSSQL.

This is done using an SQL query.

The first SQL query removes white spaces from the left of the string
update TABLENAME set COLUMN_NAME = REPLACE(LTRIM(RTRIM(COLUMN_NAME)), , )

The first SQL query removes white spaces from the right of the string
update TABLENAME set COLUMN_NAME = REPLACE(RTRIM(RTRIM(COLUMN_NAME)), , )


There are scenarios of the occurrence of spaces before and after a string and we may need to remove/trim the spaces for our use. Let us see how it is getting handled in SQL Server. Till SQL Server 2016, we have the functions called SQL LTRIM and SQL RTRIM functions. The name itself implies that LTRIM is helpful to remove the leftmost spaces and RTRIM is helpful to remove the rightmost spaces.