1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > sql char和varchar数据类型两者区别对比

sql char和varchar数据类型两者区别对比

时间:2023-06-19 21:46:43

相关推荐

sql char和varchar数据类型两者区别对比

数据库|mysql教程

sql char,sql varchar

数据库-mysql教程

导航 源码,ubuntu中存储池,猿人学python爬虫,php ppt,石屏seo价格lzw

本文章介绍mssql server中char和varchar数据性能对比分析,详细的利用实例来说明两者的关系,有需要了解的朋友可以参考一下。

android sdk 源码包 下载地址,ubuntu轻量级’,tomcat8开启注解,爬虫 中国气象,php 竞拍系统源码,seo优化后为什么没有效果lzw

网上在线考试源码,ubuntu 命令配置ip,python爬虫王者荣耀,php5和php7效率,如何管理seolzw

1. char

固定长度,最长n个字符。

2. varchar

最大长度为n的可变字符串。

(n为某一整数,不同,最大长度n不同)

如果我们将长度设为10:char(10), varchar(10), 然后我们将值设为: ‘apple’。

Char(10) 存储的值会是:’apple’.

Varchar(10) 存储的值会是:’apple’.

Char 和 Varchar 不能存储 Unicode 字符。

char和varchar区别:

varchar必char节省空间,但在效率上比char稍微差一些。

说varchar比char节省空间,是因为varchar是可变字符串,比如:用varchar(5)存储字符串“abc”,只占用3个字节的存储空间,而用char(5)存储,则占用5个字节(“abc ”)。

说varchar比char效率稍差,是因为,当修改varchar数据时,可能因为数据长度不同,导致数据迁移(即:多余I/O)。其中,oracle对此多余I/O描述的表达是:“行迁移”(Row Migration)。

看个实例

本次测试的SQL SERVER 2000 的char 与 varchar。

测试分三组,每次增加插入的行数,脚本如下:

实验结果:

两表存储空间比较

从国外网站找到一则实例

Fixed-length (char) or variable-length (varchar) character data types.

char[(n)]

Fixed-length non-Unicode character data with length of n bytes. n must be a value from 1 through 8,000. Storage size is n bytes. The SQL-92 synonym for char is character.

varchar[(n)]

Variable-length non-Unicode character data with length of n bytes. n must be a value from 1 through 8,000. Storage size is the actual length in bytes of the data entered, not n bytes. The data entered can be 0 characters in length. The SQL-92 synonyms for varchar are char varying or character varying.

Remarks

When n is not specified in a data definition or variable declaration statement, the default length is 1. When n is not specified with the CAST function, the default length is 30.

Objects using char or varchar are assigned the default collation of the database, unless a specific collation is assigned using the COLLATE clause. The collation controls the code page used to store the character data.

Sites supporting multiple languages should consider using the Unicode nchar or nvarchar data types to minimize character conversion issues. If you use char or varchar:

Use char when the data values in a column are expected to be consistently close to the same size.

Use varchar when the data values in a column are expected to vary considerably in size.

If SET ANSI_PADDING is OFF when CREATE TABLE or ALTER TABLE is executed, a char column defined as NULL is handled as varchar.

When the collation code page uses double-byte characters, the storage size is still n bytes. Depending on the character string, the storage size of n bytes may be less than n characters.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。