The database __ Teacher Zhao Spoke

Source: Internet
Author: User

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)









Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.