SQL-W3School- High: SQL Data Types

ylbtech-SQL-W3School- High: SQL Data Types

 

1. Back to top
1、

Data type and scope of Microsoft Access, MySQL, and SQL Server uses.

Microsoft Access Data Types

type of data description storage
Text For combining text with text or numbers. Up to 255 characters.  
Memo

Memo for a greater amount of text. It stores up to 65,536 characters.

Notes: You can not sort on memo fields. But they are searchable.

 
Byte Allowing the digital 0 to 255. 1 byte
Integer Allow numbers between -32,768 to 32,767. 2 bytes
Long Allow all interposed between the digital and 2,147,483,647 2,147,483,648 4 bytes
Single Single-precision floating point. It will handle most decimals. 4 bytes
Double Double-precision floating point. It will handle most decimals. 8 bytes
Currency

For money. Support 15 dollars, plus four decimal places.

Tip: You can select which country's currency to use.

8 bytes
AutoNumber AutoNumber field automatically assign each record number, usually starting 1 . 4 bytes
Date/Time Date and time 8 bytes
Yes/No

Logical fields can be displayed as Yes / No, True / False or the On / Off .

In the code, using the constants True and False (equivalent to 1 and 0)

Notes: Yes / No field does not allow Null values

1-bit
Ole Object Can store pictures, audio, video, or other BLOBs (Binary Large OBjects) Up to 1GB
Hyperlink It contains links to other files, including web page.  
Lookup Wizard It allows you to create a list of options that can be selected from the drop-down list. 4 bytes

MySQL Data Types

In MySQL, there are three main types: text, numeric, and date / time types.

Text type:

type of data description
CHAR(size) Save a fixed length character string (which may contain letters, numbers and special characters). Specifies the length of the string in the parenthesis. Up to 255 characters.
VARCHAR(size)

Save a variable length string (which may contain letters, numbers and special characters). Maximum size is specified in parenthesis. Up to 255 characters .

Note: If the length is greater than 255, were converted to the TEXT type.

TINYTEXT Storing a maximum length of 255 characters in a string.
TEXT Storing a maximum length of 65,535 characters in the string.
BLOB For BLOBs (Binary Large OBjects). Up to 65,535 bytes of data storage.
MEDIUMTEXT Storing a maximum length of 16,777,215 characters in a string.
MEDIUMBLOB For BLOBs (Binary Large OBjects). Contain up to 16,777,215 bytes of data.
LONGTEXT The maximum length of a string stored 4,294,967,295 characters.
LONGBLOB For BLOBs (Binary Large OBjects). 4,294,967,295 bytes of data storage.
ENUM(x,y,z,etc.)

It allows you to enter a list of possible values. You can list up to 65535 values ​​in an ENUM list. If the list does not exist in the inserted value, insert the null value.

Note: These values ​​are in the order you enter the store.

This can follow the format of the input values ​​possible: ENUM ( 'X', 'Y', 'Z')

SET Similar to ENUM, SET can contain up to 64 list items , but may be more than the value of SET a memory.

Number Type:

type of data description
TINYINT(size) -128 到 127 常规。0 到 255 无符号*。在括号中规定最大位数。
SMALLINT(size) -32768 到 32767 常规。0 到 65535 无符号*。在括号中规定最大位数。
MEDIUMINT(size) -8388608 到 8388607 普通。0 to 16777215 无符号*。在括号中规定最大位数。
INT(size) -2147483648 到 2147483647 常规。0 到 4294967295 无符号*。在括号中规定最大位数。
BIGINT(size) -9223372036854775808 到 9223372036854775807 常规。0 到 18446744073709551615 无符号*。在括号中规定最大位数。
FLOAT(size,d) 带有浮动小数点的小数字。在括号中规定最大位数。在 d 参数中规定小数点右侧的最大位数。
DOUBLE(size,d) 带有浮动小数点的大数字。在括号中规定最大位数。在 d 参数中规定小数点右侧的最大位数。
DECIMAL(size,d) 作为字符串存储的 DOUBLE 类型,允许固定的小数点

* 这些整数类型拥有额外的选项 UNSIGNED。通常,整数可以是负数或正数。如果添加 UNSIGNED 属性,那么范围将从 0 开始,而不是某个负数。

Date 类型:

数据类型 描述
DATE()

日期。格式:YYYY-MM-DD

注释:支持的范围是从 '1000-01-01' 到 '9999-12-31'

DATETIME()

*日期和时间的组合。格式:YYYY-MM-DD HH:MM:SS

注释:支持的范围是从 '1000-01-01 00:00:00' 到 '9999-12-31 23:59:59'

TIMESTAMP()

*时间戳。TIMESTAMP 值使用 Unix 纪元('1970-01-01 00:00:00' UTC) 至今的描述来存储。格式:YYYY-MM-DD HH:MM:SS

注释:支持的范围是从 '1970-01-01 00:00:01' UTC 到 '2038-01-09 03:14:07' UTC

TIME() 时间。格式:HH:MM:SS 注释:支持的范围是从 '-838:59:59' 到 '838:59:59'
YEAR()

2 位或 4 位格式的年。

注释:4 位格式所允许的值:1901 到 2155。2 位格式所允许的值:70 到 69,表示从 1970 到 2069。

* 即便 DATETIME 和 TIMESTAMP 返回相同的格式,它们的工作方式很不同。在 INSERT 或 UPDATE 查询中,TIMESTAMP 自动把自身设置为当前的日期和时间。TIMESTAMP 也接受不同的格式,比如 YYYYMMDDHHMMSS、YYMMDDHHMMSS、YYYYMMDD 或 YYMMDD。

SQL Server 数据类型

Character 字符串:

数据类型 描述 存储
char(n) 固定长度的字符串。最多 8,000 个字符。 n
varchar(n) 可变长度的字符串。最多 8,000 个字符。  
varchar(max) 可变长度的字符串。最多 1,073,741,824 个字符  
text 可变长度的字符串。最多 2GB 字符数据  

Unicode 字符串:

数据类型 描述 存储
nchar(n) 固定长度的 Unicode 数据。最多 4,000 个字符。  
nvarchar(n) 可变长度的 Unicode 数据。最多 4,000 个字符。  
nvarchar(max) 可变长度的 Unicode 数据。最多 536,870,912 个字符。  
ntext 可变长度的 Unicode 数据。最多 2GB 字符数据。  

Binary 类型:

数据类型 描述 存储
bit 允许 0、1 或 NULL  
binary(n) 固定长度的二进制数据。最多 8,000 字节。  
varbinary(n) 可变长度的二进制数据。最多 8,000 字节。  
varbinary(max) 可变长度的二进制数据。最多 2GB 字节。  
image 可变长度的二进制数据。最多 2GB。  

Number 类型:

数据类型 描述 存储
tinyint 允许从 0 到 255 的所有数字。 1 字节
smallint 允许从 -32,768 到 32,767 的所有数字。 2 字节
int 允许从 -2,147,483,648 到 2,147,483,647 的所有数字。 4 字节
bigint 允许介于 -9,223,372,036,854,775,808 和 9,223,372,036,854,775,807 之间的所有数字。 8 字节
decimal(p,s)

固定精度和比例的数字。允许从 -10^38 +1 到 10^38 -1 之间的数字。

p 参数指示可以存储的最大位数(小数点左侧和右侧)。p 必须是 1 到 38 之间的值。默认是 18

s 参数指示小数点右侧存储的最大位数。s 必须是 0 到 p 之间的值。默认是 0

5-17 字节
numeric(p,s)

固定精度和比例的数字。允许从 -10^38 +1 到 10^38 -1 之间的数字。

p 参数指示可以存储的最大位数(小数点左侧和右侧)。p 必须是 1 到 38 之间的值。默认是 18。

s 参数指示小数点右侧存储的最大位数。s 必须是 0 到 p 之间的值。默认是 0。

5-17 字节
smallmoney 介于 -214,748.3648 和 214,748.3647 之间的货币数据。 4 字节
money 介于 -922,337,203,685,477.5808 和 922,337,203,685,477.5807 之间的货币数据。 8 字节
float(n) 从 -1.79E + 308 到 1.79E + 308 的浮动精度数字数据。 参数 n 指示该字段保存 4 字节还是 8 字节。float(24) 保存 4 字节,而 float(53) 保存 8 字节。n 的默认值是 53。 4 或 8 字节
real 从 -3.40E + 38 到 3.40E + 38 的浮动精度数字数据。 4 字节

Date 类型:

数据类型 描述 存储
datetime 从 1753 年 1 月 1 日 到 9999 年 12 月 31 日,精度为 3.33 毫秒。 8 bytes
datetime2 从 1753 年 1 月 1 日 到 9999 年 12 月 31 日,精度为 100 纳秒 6-8 bytes
smalldatetime 从 1900 年 1 月 1 日 到 2079 年 6 月 6 日,精度为 1 分钟。 4 bytes
date 仅存储日期。从 0001 年 1 月 1 日 到 9999 年 12 月 31 日。 3 bytes
time 仅存储时间。精度为 100 纳秒。 3-5 bytes
datetimeoffset 与 datetime2 相同,外加时区偏移 8-10 bytes
timestamp 存储唯一的数字每当创建或修改某行时,该数字会更新。timestamp 基于内部时钟,不对应真实时间每个表只能有一个 timestamp 变量  

其他数据类型:

数据类型 描述
sql_variant 存储最多 8,000 字节不同数据类型的数据,除了 text、ntext 以及 timestamp。
uniqueidentifier 存储全局标识符 (GUID)。
xml 存储 XML 格式化数据。最多 2GB。
cursor 存储对用于数据库操作的指针的引用。
table 存储结果集,供稍后处理。
2、
2.返回顶部
 
3.返回顶部
 
4.返回顶部
 
5.返回顶部
1、
2、
 
6.返回顶部
 
warn 作者:ylbtech
出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

Guess you like

Origin www.cnblogs.com/storebook/p/11827475.html