Home Database Mysql Tutorial Mysql数据格式_MySQL

Mysql数据格式_MySQL

Jun 01, 2016 pm 01:45 PM
Chinese character English

bitsCN.com

Varchar 对每个英文(ASCII)字符都占用2个字节,对一个汉字也只占用两个字节
char 对英文(ASCII)字符占用1个字节,对一个汉字占用2个字节Varchar 的类型不以空格填满,比如varchar(100),但它的值只是"qian",则它的值就是"qian"而char 不一样,比如char(100),它的值是"qian",而实际上它在数据库中是"qian "(qian后共有96个空格,就是把它填满为100个字节)。

由于char是以固定长度的,所以它的速度会比varchar快得多!但程序处理起来要麻烦一点,要用trim之类的函数把两边的空格去掉!

ntext

可变长度 Unicode 数据的最大长度为 230 - 1 (1,073,741,823) 个字符。存储大小是所输入字符个数的两倍(以字节为单位)。ntext 在 SQL-92 中的同义词是 national text。

text

服务器代码页中的可变长度非 Unicode 数据的最大长度为 231-1 (2,147,483,647) 个字符。当服务器代码页使用双字节字符时,存储量仍是 2,147,483,647 字节。存储大小可能小于 2,147,483,647 字节(取决于字符串)。

bigint:从-2^63(-9223372036854775808)到2^63-1(9223372036854775807)的整型数据,存储大小为 8 个字节。

int:从-2^31(-2,147,483,648)到2^31-1(2,147,483,647)的整型数据,存储大小为 4 个字节。

smallint:从-2^15(-32,768)到2^15-1(32,767)的整数数据,存储大小为 2 个字节。

tinyint:从0到255的整数数据,存储大小为 1 字节。

bit:1或0的整数数据,存储大小为 1 字节。

 

Unicode 数据
在 Microsoft® SQL Server™ 2000 中,传统上非 Unicode 数据类型允许使用由特定字符集定义的字符。字符集是在安装 SQL Server 时选择的,不能更改。使用 Unicode 数据类型,列可存储由 Unicode 标准定义的任何字符,包含由不同字符集定义的所有字符。Unicode 数据类型需要相当于非 Unicode 数据类型两倍的存储空间。

Unicode 数据使用 SQL Server 中的 nchar、varchar 和 ntext 数据类型进行存储。对于存储来源于多种字符集的字符的列,可采用这些数据类型。当列中各项所包含的 Unicode 字符数不同时(至多为 4000),使用 nvarchar 类型。当列中各项为同一固定长度时(至多为 4000 个 Unicode 字符),使用 nchar 类型。当列中任意项超过 4000 个 Unicode字符时,使用 ntext 类型。

说明    SQL Server 的 Unicode 数据类型是基于 SQL-92 标准中的国家字符数据类型。SQL-92 使用前缀字符 n 标识这些数据类型及其值。

 

1.数据类型
数据类弄是数据的一种属性,表示数据所表示信息的类型。任何一种计算机语言都定义了自己的数据类型。当然,不同的程序语言都具有不同的特点,所定义的数据类型的各类和名称都或多或少有些不同。SQL Server 提供了 25 种数据类型:
·Binary [(N)]
·Varbinary [(N)]
·Char [(N)]
·Varchar[(N)]
·Nchar[(N)]
·Nvarchar[(N)]
·Datetime
·Smalldatetime
·Decimal[(p[,s])]
·Numeric[(p[,s])]
·Float[(N)]
·Real
·Int
·Smallint
·Tinyint
·Money
·Smallmoney
·Bit
·Cursor
·Sysname
·Timestamp
·Uniqueidentifier
·Text
·Image
·Ntext
 
(1)二进制数据类型
二进制数据包括 Binary、Varbinary 和 Image.
Binary 数据类型既可以是固定长度的(Binary),也可以是变长度的。
Binary[(N)] 是 n 位固定的二进制数据。其中,n 的取值范围是从 1 到 8000。其存储窨的大小是 n + 4 个字节。
Varbinary[(N)] 是 n 位变长度的二进制数据。其中,n 的取值范围是从 1 到 8000。其存储窨的大小是 n + 4个字节,不是 n 个字节。
在 Image 数据类型中存储的数据是以位字符串存储的,不是由 SQL Server 解释的,必须由应用程序来解释。例如,应用程序可以使用 BMP、TIEF、GIF 和 JPEG 格式把数据存储在 Image 数据类型中。
(2)字符数据类型
字符数据的类型包括 Char,Varchar 和 Text。
字符数据是由任何字母、符号和数字任意组合而成的数据。
Varchar 是变长字符数据,其长度不超过 8KB。Char 是定长字符数据,其长度最多为 8KB。超过 8KB 的ASCII 数据可以使用Text 数据类型存储。例如,因为 Html 文档全部都是 ASCII 字符,并且在一般情况下长度超过 8KB,所以这些文档可以 Text 数据类型存储在 SQL Server 中。
(3)Unicode 数据类型
Unicode 数据类型包括 Nchar,Nvarchar 和Ntext。
在 Microsoft SQL Server 中,传统的非 Unicode 数据类型允许使用由特定字符集定义的字符。在 SQL Server 安装过程中,允许选择一种字符集。使用 Unicode 数据类型,列中可以存储任何由Unicode 标准定义的字符。在 Unicode 标准中,包括了以各种字符集定义的全部字符。使用Unicode 数据类型,所战胜的窨是使用非 Unicode 数据类型所占用的窨大小的两倍。
在 SQL Server 中,Unicode 数据以 Nchar、Nvarchar 和 Ntext 数据类型存储。使用这种字符类型存储的列可以存储多个字符集中的字符。当列的长度变化时,应该使用 Nvarchar 字符类型,这时最多可以存储 4000 个字符。当列的长度固定不变时,应该使用 Nchar 字符类型,同样,这时最多可以存储 4000 个字符。当使用 Ntext 数据类型时,该列可以存储多于 4000 个字符。
(4)日期和时间数据类型
日期和时间数据类型包括 Datetime 和 Smalldatetime 两种类型。
日期和时间数据类型由有效的日期和时间组成。例如,有效的日期和时间数据包括"4/01/98 12:15:00:00:00 PM"和"1:28:29:15:01 AM 8/17/98"。前一个数据类型是日期在前,时间在后一个数据类型是霎时间在前,日期在后。在 Microsoft SQL Server 中,日期和时间数据类型包括Datetime 和 Smalldatetime 两种类型时,所存储的日期范围是从 1753 年 1 月 1 日开始,到 9999 年12 月 31 日结束(每一个值要求 8 个存储字节)。使用 Smalldatetime 数据类型时,所存储的日期范围是 1900 年 1 月 1日 开始,到 2079 年 12 月 31 日结束(每一个值要求 4 个存储字节)。
日期的格式可以设定。设置日期格式的命令如下:
Set DateFormat {format | @format _var|
其中,format | @format_var 是日期的顺序。有效的参数包括 MDY、DMY、YMD、YDM、MYD 和 DYM。在默认情况下,日期格式为 MDY。
例如,当执行 Set DateFormat YMD 之后,日期的格式为年 月 日 形式;当执行 Set DateFormat DMY 之后,日期的格式为 日 月有年 形式
(5)数字数据类型
数字数据只包含数字。数字数据类型包括正数和负数、小数(浮点数)和整数 。
整数由正整数和负整数组成,例如 39、25、0-2 和 33967。在 Micrsoft SQL Server 中,整数存储的数据类型是 Int,Smallint 和 Tinyint。Int 数据类型存储数据的范围大于 Smallint 数据类型存储数据的范围,而 Smallint 据类型存储数据的范围大于 Tinyint 数据类型存储数据的范围。使用 Int 数据狗昔存储数据的范围是从 -2 147 483 648 到 2 147 483 647(每一个值要求 4个字节存储空间)。使用 Smallint 数据类型时,存储数据的范围从 -32 768 到 32 767(每一个值要求2个字节存储空间)。使用 Tinyint 数据类型时,存储数据的范围是从0 到255(每一个值要求1个字节存储空间)。
精确小娄数据在 SQL Server 中的数据类型是 Decimal 和 Numeric。这种数据所占的存储空间根据该数据的位数后的位数来确定。
在SQL Server 中,近似小数数据的数据类型是 Float 和 Real。例如,三分之一这个分数记作。3333333,当使用近似数据类型时能准确表示。因此,从系统中检索到的数据可能与存储在该列中数据不完全一样。
(6)货币数据表示正的或者负的货币数量 。在 Microsoft SQL Server 中,货币数据的数据类型是Money 和 Smallmoney。Money 数据类型要求 8 个存储字节,Smallmoney 数据类型要求 4 个存储字节。
(7)特殊数据类型
特殊数据类型包括前面没有提过的数据类型。特殊的数据类型有3种,即 Timestamp、Bit 和 Uniqueidentifier。
Timestamp 用于表示SQL Server 活动的先后顺序,以二进投影的格式表示。Timestamp 数据与插入数据或者日期和时间没有关系。
Bit 由 1 或者 0 组成。当表示真或者假、ON 或者 OFF 时,使用 Bit 数据类型。例如,询问是否是每一次访问的客户机请求可以存储在这种数据类型的列中。
Uniqueidentifier 由 16 字节的十六进制数字组成,表示一个全局唯一的。当表的记录行要求唯一时,GUID是非常有用。例如,在客户标识号列使用这种数据类型可以区别不同的客户。

bitsCN.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to change Google Chrome to Chinese mode? How to change Google Chrome to Chinese mode? Mar 13, 2024 pm 07:31 PM

How to change Chinese to English in Google Chrome? Some friends want to set Google Chrome to English so that they can continuously improve their English during use. So how to set it to English? Google Chrome is Chinese by default. Below, I will show you how to set the language of Google Chrome to English. Let’s take a look. Setting steps: 1. Open [Google Chrome], as shown in the figure below. 2. Click the [three dots] menu in the upper right corner of the Google Chrome interface, as shown in the figure below. 3. After entering the menu page, find [Settings], as shown in the figure below. 4. After entering the settings page, click the [Language] option, as shown in the figure below. 5. Select [Add Language] in the language interface, as shown in the figure below.

How to solve the problem of English appearing when booting up Windows 10 computer How to solve the problem of English appearing when booting up Windows 10 computer Jul 11, 2023 pm 04:57 PM

Many friends always encounter various problems when using computers. For example, after turning on the computer, they find that the entire computer has changed to English. Many friends do not know how to set it back to Chinese. The editor below will teach you how to set up a win10 computer. How to solve the problem of English appearing when turning on the computer. 1. After turning on the computer, click "Start - Settings" in the lower left corner. As shown in the figure: 2. After entering the Windows settings interface, click "Time and Language". As shown in the figure: 3. After entering the time and language interface, click "Region and Language". As shown in the figure: 4. After entering the region and language interface, click "Manage Language Settings". As shown in the figure: 5. After entering the management interface, click "Copy Settings". As shown in the figure: 6. Enter the welcome screen settings

How to hide the English keyboard in Win11 How to hide the English keyboard in Win11 Jan 03, 2024 pm 09:45 PM

Some friends do not need to use the English keyboard, but only need to use the Chinese keyboard. At this time, they will find the English keyboard very troublesome and want to hide it. However, we cannot hide it, but we can directly delete the English input method. Let’s follow the editor. Take a look. How to hide the English keyboard in win11 1. The English keyboard cannot be hidden, but we can delete it directly in the input method. 2. First enter "Settings" through the start menu 3. Then select "Time & Language" 4. Then enter "Language & Region" and click "Addakeyboard" below to add keyboard shortcuts. 5. Then click on the input method we want, and then click the arrow in the lower left corner to move it to

How to fix the input method that comes with Windows 10 to English How to fix the input method that comes with Windows 10 to English Jan 15, 2024 pm 01:48 PM

Many friends who work on the computer use the English input method to work. At this time, they need to lock the English input. So how to lock it? Let’s take a look at the detailed methods below. How to lock the input method that comes with win10 in English: 1. Click the input method logo in the lower right corner of the desktop, and then click "Language Preferences". 2. Then click "Add preferred language" under the preferred language. 3. Enter English in the dialog box and click to install the language. 4. After the installation is complete, click "Set as default language".

The internal code of a Chinese character requires several bytes to store The internal code of a Chinese character requires several bytes to store Dec 14, 2020 pm 05:45 PM

The internal code of a Chinese character requires 2 bytes to store. In the popular Chinese character system in China, the internal code of a Chinese character occupies 2 bytes. Because the Chinese character processing system must ensure compatibility between Chinese and Western languages, ambiguity will occur when ASCII codes and Chinese character national standard codes exist in the system. ; To this end, the Chinese character internal code should be appropriately processed and transformed into the national standard code.

Master the skills of PHP processing Chinese character transcoding Master the skills of PHP processing Chinese character transcoding Mar 28, 2024 pm 03:47 PM

PHP is a widely used server-side scripting language commonly used for website development. During website development, we often encounter the need to transcode Chinese characters, especially when dealing with Chinese characters. Mastering the skills of PHP in processing Chinese character transcoding can effectively avoid problems such as garbled characters and improve the stability and user experience of the website. 1.utf8_encode and utf8_decode functions In PHP, you can use the utf8_encode and utf8_decode functions to encode and decode Chinese characters.

How to set the language of Windows 10 Home Edition to English How to set the language of Windows 10 Home Edition to English Feb 14, 2024 pm 07:36 PM

In the Windows operating system, we can easily enable various languages ​​to facilitate system display, thereby further enhancing user experience and communication efficiency. Open the system settings interface, then select the "Input method and keyboard" option, and then click to add the selected language in this interface. How to set the Windows 10 Home Edition language to English 1. Click Start to enter Settings 2. Click to enter Time and Language 3. Select "Region and Language", then click "Add Language" 4. Select English (unitedstates)

In-depth understanding of the principle of converting Chinese characters to UTF-8 encoding in PHP In-depth understanding of the principle of converting Chinese characters to UTF-8 encoding in PHP Mar 28, 2024 pm 02:44 PM

The principle of converting Chinese characters to UTF-8 encoding actually involves the concept of character encoding. In computers, text characters need to be represented and stored in the form of numbers, and different character encoding schemes specify the correspondence between different characters and numbers. UTF-8 is a commonly used character encoding method. It supports characters worldwide and uses a variable-length encoding method, which can effectively represent characters in various languages ​​and is especially suitable for the Unicode character set. As a common server-side scripting language, PHP also provides

See all articles