kenan
kenan

Reputation: 127

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?

Upvotes: 0

Views: 351

Answers (2)

Halis Yılboğa
Halis Yılboğa

Reputation: 900

you should use nvarchar

SQL Server provides both datatypes to store character information. For the most part the two datatypes are identical in how you would work with them within SQL Server or from an application. The difference is that nvarchar is used to store unicode data, which is used to store multilingual data in your database tables. Other languages have an extended set of character codes that need to be saved and this datatype allows for this extension. If your database will not be storing multilingual data you should use the varchar datatype instead. The reason for this is that nvarchar takes twice as much space as varchar, this is because of the need to store the extended character codes for other languages from

Upvotes: 0

Ry-
Ry-

Reputation: 225054

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

Upvotes: 4

Related Questions