7

I just installed Microsoft SQL Server 2008 R2 to test with LINQ to SQL.

I have a table with one column of type nchar(20) and two rows: '123' and 'Test'.

If I query all the rows from that table and wrap each value with "'" I get the following:

'123 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ' ( _ is a space)

'Test _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ' ( _ is a space)

SQL Server seems to be filling the unused space (because the column is a 20 byte nchar) with spaces.

What can I do to prevent this from happening?

1
  • 1
    Just to add that it is a 40 byte nchar not 20 as in your question. Unicode datatypes take double the space. Commented Aug 6, 2010 at 22:18

3 Answers 3

18

Use nvarchar instead of nchar. nchar is a fixed width field that is filled with spaces, as you're seeing.

Sign up to request clarification or add additional context in comments.

Comments

2

Change the column type to nvarchar.

See nchar and nvarchar.

Comments

1

you need nvarchar, it is flexible.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.