Search code examples
sqlsql-servert-sqlsqldatatypes

SQL Server : whitespaces in rows


I have this problem where in my database I get lots of empty spaces after my text,

In my email I have "[email protected]+_________________________________________" lots of spaces

My email row is nchar(255)

and that is happening to all of my tables

Can anyone explain to me why is this happening and how to fix it?


Solution

  • CHAR and NCHAR will automatically right-pad a string with spaces to meet the defined length. Use NVARCHAR(255) instead of NCHAR(255).