What is the difference between char, nchar, varchar, and nvarchar in SQL Server?

nchar:

 1) support unicode characters
 2) fixed length variable
 3) Maximum length of 4,000 characters.
 3) it will reserve  storage space for number of size you specify.

e.g: nchar(10) if you store only 3   characters and it will reserve space for 10 characters and remaining 7 character space  will be waste.

char:

 1) does not support unicode character.
 2) fixed length variable 
 3) Maximum length of 8,000 characters.
 4) it will reserve  storage space for number of size you specify.

 e.g: nchar(10) if you store only 3   characters and it will reserve space for 10 characters and remaining 7 character space  will be waste.


varchar:

 1) does not support unicode character.
 2) variable length variable
 3) varchar(n) - Maximum 8,000 characters and varchar(max) - Maximum 1,073,741,824 characters
 4) it will reserve storage space for the data you store.

e.g: nvarchar(50) if you store only 25   characters and it will reserve space only for 25 characters and remaining 25 character space  will not allocate  in memory.

nvarchar:

 1) support unicode characters
 2) variable length variable
 3) nvarchar(n) - Maximum 4,000 characters and nvarchar(max) - 536,870,912 characters
 4) it will reserve storage space for the data you store.

e.g: nvarchar(50) if you store only 25   characters and it will reserve space only for 25 characters and remaining 25 character space  will not allocate  in memory.

0 comments :

Post a Comment