What is Difference between nchar and nvarchar

nchar and nvarchar are indicates that it will store Unicode characters whereas char and varchar can’t store Unicode characters.

Char and nchar are fixed-length datatype.

Fixed-length datatype that means it will occupy space whatever number you have specified at the time of table definition. Even if you don’t use all that space.

Varchar and nvarchar are Variable-length datatype.

Variable-Length datatype that means it will use only that much space that required by data in the table. It will not reserve space as compare to char and nchar in fixed length.

Nchar and nvarchar will take up twice as much storage space, so it may be wise to use them only if you need Unicode support.

DECLARE @Test TABLE
(
varchar_col VARCHAR (10),
nvarchar_col NVARCHAR (10),
char_col char (10),
nchar_col nchar(10)
)

INSERT INTO @Test VALUES (‘SQLServer’,’SQLServer’,’SQLServer’,’SQLServer’)

SELECT                LEN(varchar_col)                            AS [LEN(varchar_col)],
DATALENGTH(varchar_col)       AS [DATALENGTH],
LEN(nvarchar_col)                          AS [LEN(nvarchar_col)],
DATALENGTH(nvarchar_col)    AS [DATALENGTH],
LEN(char_col)                                   AS [LEN(char_col)],
DATALENGTH(char_col)             AS [DATALENGTH],
LEN(nchar_col)                                AS [LEN(nchar_col)],
DATALENGTH(nchar_col)           AS [DATALENGTH]
FROM @Test

sql server query output

 

What is UNICODE Character in Sql server?

Leave a Reply

  

  

  


7 + = 8