Just a learner
Just a learner

Reputation: 28572

Why I can insert non-ascii characters into VARCHAR column and correctly get it back?

Below is my code sample.

DECLARE @a TABLE (a VARCHAR(20));
INSERT  @a
        (a)
VALUES  ('中');

SELECT  *
FROM    @a;

I'm using SQL Server Management Studio to run it. My question is, why I can insert non-ascii characters into VARCHAR column and correctly get it back? As I understand, VARCHAR type is only for ascii characters and the NVARCHAR is for unicode characters. Anyone can help to explain it please? I'm on Windows 7 with SQL Server 2014 developer edition.

Upvotes: 1

Views: 1921

Answers (2)

Tim
Tim

Reputation: 2912

The codepage used to store the varchar data varies by DB collation.

https://msdn.microsoft.com/en-us/library/ms189617.aspx

Varchar is 8 bits, so you may have a different collation, or you may have gotten lucky on where your character falls on the code set

Upvotes: 2

sqluser
sqluser

Reputation: 5672

You can find the ASCII and Extended ASCII characters below.

ASCII

enter image description here

Extended ASCII

enter image description here

I don't believe '中' is an ASCII character.

www.asciitable.com

Upvotes: 0

Related Questions