search
HomeDatabaseMysql Tutorial SQL Server数据类型

转载: 数据类型是数据的一种属性,是数据所表示信息的类型。任何一种语言都有它自己所固有的数据类型,SQL Server提供一下25种固有的数据类型。 SQL Server数据类型一览表 ·Binary [(n)] ·Varbinary [(n)] ·Char [(n)] ·Varchar[(n)] ·Nchar[(n)] ·Nv

转载:

   数据类型是数据的一种属性,是数据所表示信息的类型。任何一种语言都有它自己所固有的数据类型,SQL Server提供一下25种固有的数据类型。

SQL Server数据类型一览表
·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 固定长度(最多为8K)的二进制数据类型。

binary [ ( n ) ]
固定长度的 n 个字节二进制数据。N 必须从 1 到 8,000。存储空间大小为 n+4 字节。

·varbinary 可变长度(最多为8K)的二进制数据类型。

varbinary [ ( n ) ]
      n 个字节变长二进制数据。n 必须从 1 到 8,000。存储空间大小为实际输入数据长度 +4
      个字节,而不是 n 个字节。输入的数据长度可能为 0 字节。在 SQL-92 中 varbinary 的
      同义词为 binary varying。

·image 用来存储长度超过 8 KB 的可变长度的二进制数据。
      除非数据长度超过 8KB,否则一般宜用 varbinary 类型来存储二进制数据。一般用来存放 Microsoft Word 文档、Microsoft Excel 电子表格、包含位图的图像、图形交换格式 (GIF) 文件和联合图像专家组 (JPEG) 文件。
      在 Image 数据类型中存储的数据是以位字符串存储的,不是由 SQL Server 解释的,必须由应用程序来解释。例如,应用程序可以使用BMP、TIEF、GIF 和 JPEG 格式把数据存储在 Image 数据类型中。

2、字符数据类型
      字符数据由字母、符号和数字组成。使用 char、varchar 和 text 数据类型存储。
·char 固定长度(不超过 8 KB)的字符数据类型。

      char[(n)]
      长度为 n 个字节的固定长度且非 Unicode 的字符数据。n 必须是一个介于 1 和 8,000
      之间的数值。存储大小为 n 个字节。char 在 SQL-92 中的同义词为 character。

·varchar 可变长度(不超过 8 KB)的字符数据类型。

      varchar[(n)]
      长度为 n 个字节的可变长度且非 Unicode 的字符数据。n 必须是一个介于 1 和 8,000
      之间的数值。存储大小为输入数据的字节的实际长度,而不是 n 个字节。所输入的数据字
      符长度可以为零。varchar 在SQL-92 中的同义词为char varying 或character varying。

·text 数据类型的列可用于存储大于 8KB 的 ASCII 字符。
      例如,由于 HTML 文档均由 ASCII 字符组成且一般长于 8KB,所以用浏览器查看之前应在 SQL Server 中存储在 text 列中。

3、Unicode数据类型
      使用 Unicode 数据类型,列可存储由 Unicode 标准定义的任何字符,包含由不同字符集定义的所有字符。Unicode 数据使用 SQL Server 中的 nchar、varchar 和 ntext 数据类型进行存储。
·nchar 固定长度(至多为 4000 个 Unicode 字符)的Unicode数据类型。

      nchar(n) 包含n 个字符的固定长度Unicode字符数据。n的值必须介于1与4,000之间。存储大小为n字
      节的两倍。nchar 在 SQL-92 中的同义词为 national char 和 national character。

·nvarchar ( varchar ) 是可变长度 Unicode 数据的数据类型。

      nvarchar(n) 包含 n 个字符的可变长度 Unicode 字符数据。n 的值必须介于 1 与 4,000 之间。
      字节的存储大小是所输入字符个数的两倍。所输入的数据字符长度可以为零。nvarchar 在 SQL-92 中的同义词为 national char varying 和 national character varying。

·ntext 当列中任意项超过 4000 个 Unicode字符时使用。

4、日期和时间数据类型
      日期和时间数据由有效的日期或时间组成。例如,有效日期和时间数据既包括"4/01/98 12:15:00:00:00 PM",也包括"1:28:29:15:01 AM 8/17/98"。在 Microsoft SQL Server 2000 中,日期和时间数据使用 datetime 和 smalldatetime 数据类型存储。
·datetime
数据类型存储从 1753 年 1 月 1 日至 9999 年 12 月 31 日的日期。
      每个数值要求 8 个字节的存储空间。

·smalldatetime
数据类型存储从 1900 年 1 月 1 日至 2079 年 6 月 6 日的日期。
      每个数值要求 4 个字节的存储空间。

·设置日期
格式的命令如下:
      Set DateFormat {format | @format _var|
      其中,format | @format_var 是日期的顺序。有效的参数包括 MDY、DMY、YMD、
      YDM、MYD 和 DYM。在默认情况下,日期格式为MDY。

5、数字数据类型
      数字数据只包含数字。数字数据包括正数、负数、小数、分数和整数。
·整型数据
整型数据由负整数或正整数组成,如 -15、0、5 和 2509。在 Microsoft SQL Server
      2000 中,整型数据使用 bigint、int、smallint 和 tinyint 数据类型存储。bigint 数据类
      型可存储的数字范围比 int 数据类型广。int 数据类型比 smallint 数据类型的存储范围
      大,而 smallint 的数值范围又比 tinyint 类型大。

      bigint 存储从-2^63 (-9223372036854775808)到2^63-1(9223372036854775807) 范围内的
        数字。存储大小为 8 个字节。

int 存储范围是-2,147,483,648至2,147,483,647(每个值需4个字节的存储空间)。

smallint 存储范围只有 -32,768 至 32,767(每个值需 2 个字节的存储空间)。

      tinyint 只能存储 0 至 255 范围内的数字(每个值需 1 个字节的存储空间)。

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
What are stored procedures in MySQL?What are stored procedures in MySQL?May 01, 2025 am 12:27 AM

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

How does query caching work in MySQL?How does query caching work in MySQL?May 01, 2025 am 12:26 AM

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

What are the advantages of using MySQL over other relational databases?What are the advantages of using MySQL over other relational databases?May 01, 2025 am 12:18 AM

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

How do you handle database upgrades in MySQL?How do you handle database upgrades in MySQL?Apr 30, 2025 am 12:28 AM

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

What are the different backup strategies you can use for MySQL?What are the different backup strategies you can use for MySQL?Apr 30, 2025 am 12:28 AM

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

What is MySQL clustering?What is MySQL clustering?Apr 30, 2025 am 12:28 AM

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

How do you optimize database schema design for performance in MySQL?How do you optimize database schema design for performance in MySQL?Apr 30, 2025 am 12:27 AM

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

How can you optimize MySQL performance?How can you optimize MySQL performance?Apr 30, 2025 am 12:26 AM

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

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

Video Face Swap

Video Face Swap

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

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.