Today studied char, Nchar,varchar,nvarchar, at the beginning of the time to listen to a little vague, back to see the notes around the note probably understand, I feel that Mr. Zhao is still very clear logic clearer
Reprint the Lesson Notes
Common data types in SQL Server:
1. Image type, used to store byte[]
2. String type
Char
NChar
varchar
nvarchar
Text
ntext
varchar (max)
nvarchar (max)
All of these data types represent strings.
--------------------------------------------------------------
The difference between n and without N:
A char (2) indicates that 2 bytes can be stored. ab,12, Zhao
Data type without n, storing double-byte characters such as Chinese, occupies 2 bytes, stores English, numbers and so on each character occupies 1 bytes.
NCHAR (2), with N, whether stored in Chinese or English, numbers, etc., each character occupies two bytes. NCHAR (2) indicates that two characters can be stored, and each character occupies 2 bytes.
Zhaogzhang
These data types without n can be set to a maximum length of 8000, and these data types with n can be set to a maximum length of 4000.
CHAR (8000)
varchar (8000)
NCHAR (4000)
nvarchar (4000)
-------------------------------------------------------------
The difference with Var and without Var:
Like what:
varchar
nvarchar
---------
Char
NChar
The representation with VAR is: variable length.
The representation without VAR is: fixed length.
Fixed length, storing 1 characters is also to occupy 10 bytes, will automatically fill 9 spaces
char (10) 1
1111111111
Variable lengths, which dynamically reallocate storage space based on the actual size of the data being stored, saves storage space relatively.
varchar (10) 1
11111
10, which represents a maximum of 10 bytes, if the stored data exceeds 10 bytes, then both fixed-length and variable-length will be an error.
------------------
Text
ntext
varchar (max)
nvarchar (max)