[Database] learn basic SQL data types

Numeric types

Exact type

type of data Use storage Explanation
bit First place Keep only 0 or 1
tinyint 1 byte Range 0 to 255
smallint 2 bytes Range of -2 15 to 2 15 -1, i.e. -32768 to 32767
int 4 bytes Range of -2 31 is to 2 31 is -1, i.e., 2,147,483,648 - 2,147,483,647
bigint 8 bytes Range of -2 63 is to 2 63 is -1
decimal(p,s) And related precision p represents the number of decimal places and the left and right, s represents the number of digits to the right of the decimal point, p ranges from 1 to 38, default is 18. S ranges from 0 to p, the default is 0
numeric(p,s) And related precision p represents the number of decimal places and the left and right, s represents the number of digits to the right of the decimal point, p ranges from 1 to 38, default is 18. S ranges from 0 to p, the default is 0
smallmoney 4 bytes Maximum 214748.3647
money 8 bytes 922,337,203,685,477.5808 maximum value, this value is actually 2 63 is -1 to move the decimal point to give

Approximation type

type of data Use storage Explanation
float(n) Depending on n n is the number of bits of the mantissa values stored float, n ranges from 1 to 53, the default value is 53.
SQL Server, if n is between 1 and 24, n regarded as 24, n 25 to 53, 53 n regarded.
When the value of n is 24, 4 bytes. The value of n is 53, 8 bytes.
Range divided into three sections, 1.79 × 1 0 308 2.23 × 1 0 308 0 2.23 × 1 0 308 1.79 × 1 0 308 -1.79 \ times10 ^ {308} to -2.23 \ times10 ^ {- 308}, 0,2.23 \ times10 ^ {- 308} to 1.79 \ times10 ^ {308}
real 4 bytes Range divided into three sections, 3.40 × 1 0 38 1.18 × 1 0 38 -3.40 \ times10 ^ {38} to -1.18 \ times10 ^ {- 38} ,0, 1.18 × 1 0 38 3.40 × 1 0 38 1.18 \ times10 ^ {- 38} to 3.40 \ times10 ^ {38}

Text Types

Ordinary character encoding

Each English character occupies one byte, two bytes for each character

type of data Use storage Explanation
char(n) n bytes Fixed length, n ranges from 1 to 8000
varchar(n) Data storage and related storage of an English characters occupy one byte Variable length, n represents the maximum length of the string stored, n ranges from 1 to 8000
text And storing data related to store a two-byte characters representing Variable-length string maximum length of 2 31 is -1 bytes

Unicode character encoding

Each character in English and Chinese characters are two bytes

type of data Use storage Explanation
nchar(n) n bytes Fixed length, n ranges from 1 to 4000
nvarchar(n) Data storage and related storage of an English characters occupy two bytes Variable length, n represents the maximum length of the string stored, n ranges from 1 to 4000
ntext And storing data related to store a two-byte characters representing Variable-length string maximum length of 2 30 -1 or kanji characters

Date Time Type

type of data Use storage Explanation
data 3 byte Range 0001/01/01 to 9999/12/31
time 5 bytes Range 00:00: 00.0000000 to 23: 59: 59.9999999
datetime 8 bytes 1753/01/01/00 range: 00:00 to 9999/12/31/23: 59: 59: 997
smalldate 4 bytes 1900/01/01/00 range: 00:00 to 2079/06/06/23: 59: 59

Binary type

type of data Use storage Explanation
binary(n) n bytes Fixed-length binary data, n ranges from 1 to 8000
varbinary(n) And related data stored Variable-length binary data, n represents the maximum storage bytes, n ranges from 1 to 8000
image And related data stored 长度可变的二进制数据,存储的最大值是231-1个字节,约等于2GB
varbinary(max) 与存放的数据有关 代替image
发布了13 篇原创文章 · 获赞 13 · 访问量 451

Guess you like

Origin blog.csdn.net/weixin_44611096/article/details/105024065