search
Mysql data formatDec 02, 2016 pm 02:46 PM
mysql

Varchar occupies 2 bytes for each English (ASCII) character, and only occupies two bytes for each Chinese character.
char occupies 1 byte for English (ASCII) characters, and 2 bytes for each Chinese character. Varchar The type is not filled with spaces, such as varchar(100), but its value is only "qian", then its value is "qian" and char is different, such as char(100), its value is "qian", In fact, it is "qian" in the database (there are 96 spaces after qian, which means it is filled to 100 bytes).

Since char is of fixed length, it is much faster than varchar! But the program is a little more troublesome to process. You need to use functions like trim to remove the spaces on both sides!

ntext

Variable length The maximum length of Unicode data is 230 - 1 (1,073,741,823) characters. The storage size is twice the number of characters entered (in bytes). The SQL-92 synonym for ntext is national text.

text

The maximum length of variable-length non-Unicode data in the server code page is 231-1 (2,147,483,647) characters. When the server code page uses double-byte characters, the storage amount is still 2,147,483,647 bytes. Storage size may be less than 2,147,483,647 bytes (depending on the string).

bigint: Integer data from -2^63(-9223372036854775808) to 2^63-1(9223372036854775807), storage size is 8 bytes.

int: Integer data from -2^31(-2,147,483,648) to 2^31-1(2,147,483,647), storage size is 4 bytes.

smallint: Integer data from -2^15(-32,768) to 2^15-1(32,767), storage size is 2 bytes.

tinyint: Integer data from 0 to 255, storage size is 1 byte.

bit: Integer data of 1 or 0, storage size is 1 byte.

Unicode Data
In Microsoft® SQL Server® 2000, non-Unicode data types traditionally allowed the use of characters defined by a specific character set. The character set is selected when SQL Server is installed and cannot be changed. Using Unicode data types, a column can store any character defined by the Unicode standard, including all characters defined by different character sets. Unicode data types require twice the storage space of non-Unicode data types.

Unicode data is stored using the nchar, varchar, and ntext data types in SQL Server. Use these data types for columns that store characters from multiple character sets. Use the nvarchar type when the items in the column contain a different number of Unicode characters (up to 4000). Use the nchar type when the items in the column are of the same fixed length (up to 4000 Unicode characters). When any item in the column exceeds 4000 Unicode characters, use the ntext type.

Explanation The Unicode data type of SQL Server is based on the national character data type in the SQL-92 standard. SQL-92 uses the prefix character n to identify these data types and their values.

1. Data type
Data type is an attribute of data, indicating the type of information represented by the data. Every computer language defines its own data types. Of course, different programming languages ​​have different characteristics, and the types and names of the defined data types are more or less different. SQL Server provides 25 data types:
·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
·T imestamp
·Uniqueidentifier
·Text
·Image
·Ntext

(1) Binary data type
Binary data includes Binary , Varbinary and Image.
Binary data type can be either fixed length (Binary) or variable length.
Binary[(N)] is n-bit fixed binary data. Among them, the value range of n is from 1 to 8000. Its storage size is n + 4 bytes.
Varbinary[(N)] is n-bit variable-length binary data. Among them, the value range of n is from 1 to 8000. The size of its storage is n + 4 bytes, not n bytes.
Data stored in the Image data type is stored as a bit string and is not interpreted by SQL Server and must be interpreted by the application. For example, applications can store data in the Image data type using BMP, TIEF, GIF, and JPEG formats.
(2)Character data type
Character data types include Char, Varchar and Text.
Character data is data composed of any combination of letters, symbols and numbers.
Varchar is variable-length character data, its length does not exceed 8KB. Char is fixed-length character data with a maximum length of 8KB. ASCII data exceeding 8KB can be stored using the Text data type. For example, because HTML documents are all ASCII characters and are typically more than 8KB in length, these documents can be stored in SQL Server with the Text data type.
(3)Unicode data types
Unicode data types include Nchar, Nvarchar and Ntext.
In Microsoft SQL Server, traditional non-Unicode data types allow the use of characters defined by a specific character set. During SQL Server installation, you are allowed to select a character set. Using Unicode data types, any character defined by the Unicode standard can be stored in a column. In the Unicode standard, all characters defined in various character sets are included. Using Unicode data types, the space occupied is twice the size of the space occupied by using non-Unicode data types.
In SQL Server, Unicode data is stored in Nchar, Nvarchar and Ntext data types. Columns stored using this character type can store characters from multiple character sets. When the column length varies, the Nvarchar character type should be used, which can store up to 4000 characters. The Nchar character type should be used when the length of the column is fixed, and again, a maximum of 4000 characters can be stored. When using the Ntext data type, the column can store more than 4000 characters.
(4)Date and time data types
Date and time data types include Datetime and Smalldatetime.
Date and time data types consist of valid dates and times. For example, valid date and time data include "4/01/98 12:15:00:00:00 PM" and "1:28:29:15:01 AM 8/17/98". The former data type has the date in front and the time in the back. The latter data type has the instant in front and the date in the back. In Microsoft SQL Server, when the date and time data types include Datetime and Smalldatetime, the stored date range starts from January 1, 1753 and ends on December 31, 9999 (each value requires 8 storage bytes). When using the Smalldatetime data type, the stored date range begins on January 1, 1900, and ends on December 31, 2079 (each value requires 4 bytes of storage).
The date format can be set. The command to set the date format is as follows:
Set DateFormat {format | @format _var|
Where format | @format_var is the order of dates. Valid parameters include MDY, DMY, YMD, YDM, MYD, and DYM. By default, the date format is MDY.
For example, after executing Set DateFormat YMD, the format of the date is in the form of year, month and day; when executing Set DateFormat DMY, the format of the date is in the form of day, month and year
(5) Numeric data type
Numeric data only contains numbers. Numeric data types include positive and negative numbers, decimals (floating point numbers), and integers.
Integers consist of positive and negative integers, such as 39, 25, 0-2, and 33967. In Microsoft SQL Server, the data types for integer storage are Int, Smallint and Tinyint. The Int data type stores data in a larger range than the Smallint data type, and the Smallint data type stores data in a larger range than the Tinyint data type. The range of data stored using Int data is from -2 147 483 648 to 2 147 483 647 (each value requires 4 bytes of storage space). When using the Smallint data type, the range of stored data is from -32 768 to 32 767 (each value requires 2 bytes of storage space). When using the Tinyint data type, the range of stored data is from 0 to 255 (each value requires 1 byte of storage space).
The data types of precise Xiaolou data in SQL Server are Decimal and Numeric. The storage space occupied by this data is determined based on the number of bits after the number of bits of the data.
In SQL Server, the data types for approximate decimal data are Float and Real. For example, the fraction one third is written as . 3333333, accurately represented when using approximate data types. Therefore, the data retrieved from the system may not be exactly the same as the data stored in the column.
(6) Currency data represents a positive or negative currency quantity. In Microsoft SQL Server, the data types for monetary data are Money and Smallmoney. The Money data type requires 8 bytes of storage, and the Smallmoney data type requires 4 bytes of storage.
(7) Special data types
Special data types include data types not mentioned before. There are three special data types, namely Timestamp, Bit and Uniqueidentifier.
Timestamp is used to represent the sequence of SQL Server activities, expressed in binary projection format. Timestamp data has nothing to do with inserted data or dates and times.
Bit consists of 1 or 0. The Bit data type is used when representing true or false, ON or OFF. For example, a client request that asks for every access can be stored in a column of this data type.
Uniqueidentifier consists of 16 bytes of hexadecimal numbers, representing a globally unique one. GUIDs are very useful when the rows of a table must be unique. For example, use this data type in a customer identification number column to distinguish between different customers.


Statement
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
图文详解mysql架构原理图文详解mysql架构原理May 17, 2022 pm 05:54 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

mysql怎么替换换行符mysql怎么替换换行符Apr 18, 2022 pm 03:14 PM

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

mysql的msi与zip版本有什么区别mysql的msi与zip版本有什么区别May 16, 2022 pm 04:33 PM

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

mysql怎么去掉第一个字符mysql怎么去掉第一个字符May 19, 2022 am 10:21 AM

方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

mysql怎么将varchar转换为int类型mysql怎么将varchar转换为int类型May 12, 2022 pm 04:51 PM

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

MySQL复制技术之异步复制和半同步复制MySQL复制技术之异步复制和半同步复制Apr 25, 2022 pm 07:21 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

带你把MySQL索引吃透了带你把MySQL索引吃透了Apr 22, 2022 am 11:48 AM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

mysql怎么判断是否是数字类型mysql怎么判断是否是数字类型May 16, 2022 am 10:09 AM

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!