developerasun / myCodeBox-web

Open source code box for web developers.
Apache License 2.0
5 stars 0 forks source link

[RESEARCH] database/date type: varchar and nchar #260

Open developerasun opened 2 years ago

developerasun commented 2 years ago

topic : understanding varchar & nchar type in database

read this

So what is varchar in SQL? As the name suggests, varchar means character data that is varying. Also known as Variable Character, it is an indeterminate length string data type. It can hold numbers, letters and special characters. Microsoft SQL Server 2008 (and above) can store up to 8000 characters as the maximum length of the string using varchar data type.

SQL varchar usually holds 1 byte per character and 2 more bytes for the length information. It is recommended to use varchar as the data type when columns have variable length and the actual data is way less than the given capacity.

# variable characters up to 20.
varchar(20)

A n-char is also a string of words that can store unicode data. nchar stands for national character. It takes up two bytes to store the data and can store upto 4000 chars. Unicode data refers to a universal coding standard for letters and other data. Each one is uniquely identified by designating a numeric value.

It uses ASCII standards to store the data.

# national characters up to 2 btyes, meaning one character.
nchar(2)

reference