Search code examples
sqlsql-serverspacessqldatatypes

SQL Server auto spaces


I create a table in Microsoft SQL Server Management Studio with a datatype nchar(100) in it.

If I put some data in it, then it automatically adds spaces at the end of my word I guess to fit the 100..

How can I edit this so it doesn't add spaces?

Thx


Solution

  • NCHAR and CHAR are fixed size types - that means that if the data inserted is not large enough, spaces will be inserted.

    You need to change the type of the fields to NVARCHAR for variable length data.

    See nchar and nvarchar (Transact-SQL) on MSDN for details.