VARCHAR 详解
varchar(20):20指的是表中的a字段能存储的最大字符个数
In contrast to CHAR
, VARCHAR
values are stored as a 1-byte or 2-byte length prefix plus data.
The length prefix indicates the number of bytes in the value.
A column uses one length byte if values require no more than 255 bytes,
two length bytes if values may require more than 255 bytes.
mysql> create table t1( a varchar());
Query OK, rows affected (0.27 sec)
mysql> show create table t1;
+-------+---------------------------------------------------------------
| Table | Create Table
+-------+---------------------------------------------------------------
| t1 | CREATE TABLE `t1` (
`a` varchar() DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+---------------------------------------------------------------
row in set (0.00 sec)
mysql> insert into t1 select repeat("a",);
ERROR (): Data too long for column 'a' at row
mysql> insert into t1 select repeat("a",);
Query OK, row affected (0.09 sec)
Records: Duplicates: Warnings:
mysql> insert into t1 select repeat("我",);
ERROR (): Data too long for column 'a' at row
mysql> insert into t1 select repeat("我",);
Query OK, row affected (0.11 sec)
Records: Duplicates: Warnings:
mysql> insert into t1 select "我我我我我我我我我我我我我我我我我我我1";
Query OK, row affected (0.09 sec)
Records: Duplicates: Warnings:
mysql> insert into t1 select "我我我我我我我我我我我我我我我我我我我11";
ERROR (): Data too long for column 'a' at row
varchar 存储极限:
表为utf8字符集:
mysql> show create table a;
+-------+-------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------+
| a | CREATE TABLE `a` (
`a` varchar() DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+-------------------------------------------------------------------------------------------+
row in set (0.01 sec)
mysql> create table a( a varchar());
ERROR (): Column length too big for column 'a' (max = ); use BLOB or TEXT instead
mysql> create table a( a varchar());
ERROR (): Column length too big for column 'a' (max = ); use BLOB or TEXT instead
mysql> create table a( a varchar());
ERROR (): Row size too large. The maximum row size for the used table type, not counting BLOBs, is . This includes st
eck the manual. You have to change some columns to TEXT or BLOBs
mysql> create table a( a varchar());
Query OK, rows affected (0.31 sec)
表为latin1字符集:
mysql> create table a1 ( a varchar())charset=latin1;
ERROR (): Row size too large. The maximum row size for the used table type, not counting BLOBs,
eck the manual. You have to change some columns to TEXT or BLOBs
mysql> create table a1 ( a varchar())charset=latin1;
ERROR (): Row size too large. The maximum row size for the used table type, not counting BLOBs,
eck the manual. You have to change some columns to TEXT or BLOBs
mysql> create table a1 ( a varchar())charset=latin1;
ERROR (): Row size too large. The maximum row size for the used table type, not counting BLOBs,
eck the manual. You have to change some columns to TEXT or BLOBs
mysql> create table a1 ( a varchar())charset=latin1;
Query OK, rows affected (0.33 sec)
不能插入汉字:
mysql> insert into a1 select repeat("我",);
ERROR (HY000): Incorrect string value: '\xE6\x88\x91\xE6\x88\x91...' for column 'a' at row
mysql> insert into a1 select "我";
ERROR (HY000): Incorrect string value: '\xE6\x88\x91' for column 'a' at row 1 mysql> insert into a1 select repeat("a",);
Query OK, row affected (0.17 sec)
Records: Duplicates: Warnings:
VARCHAR 详解的更多相关文章
- MySQL数据类型varchar详解
1.varchar(N)的逻辑意义从MySQL 4.1开始,varchar(N)中的N指的是该字段最多能存储多少个字符(characters),不是字节数.不管是一个中英文字符或者数字.或者一个汉字, ...
- CHAR与VARCHAR详解
前言: 前面写过一篇介绍int类型的文章,一直想写一篇介绍字符串字段类型的文章,一直拖着也没思路要怎么下手.最近多关注了下这方面的文章,决定还是把拖了好久的文章了结了吧.本篇文章主要会介绍字符串类型 ...
- MySQL中的char与varchar详解
mysql中char与varchar的区别: char:定长,效率高,一般用于固定长度的表单提交数据存储 :例如:身份证号,手机号,电话,密码等 varchar:不定长,效率偏低 1.varchar ...
- mysql中char和varchar详解
一.首先创建表. CREATE TABLE `t1` ( `id` int(11) DEFAULT NULL, `a` char(255) DEFAULT NULL) ENGINE=InnoDB DE ...
- [原创]mybatis详解说明
mybatis详解 2017-01-05MyBatis之代理开发模式1 mybatis-Dao的代理开发模式 Dao:数据访问对象 原来:定义dao接口,在定义dao的实现类 dao的代理开发模式 只 ...
- Python中操作mysql的pymysql模块详解
Python中操作mysql的pymysql模块详解 前言 pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同.但目前pymysql支持python3.x而后者不支持 ...
- MySQL 数据类型 详解
MySQL 数据类型 详解 MySQL 的数值数据类型可以大致划分为两个类别,一个是整数,另一个是浮点数或小数.许多不同的子类型对这些类别中的每一个都是可用的,每个子类型支持不同大小的数据,并且 My ...
- SQL注入攻防入门详解
=============安全性篇目录============== 本文转载 毕业开始从事winfrm到今年转到 web ,在码农届已经足足混了快接近3年了,但是对安全方面的知识依旧薄弱,事实上是没机 ...
- SQL Server时间粒度系列----第8节位运算以及设置日历数据表节假日标志详解
本文目录列表: 1.位运算 2.设置日历数据表节假日标志 3.总结语 4.参考清单列表 位运算 SQL Server支持的按位运算符有三个,分别为:按位与(&).按位或(|).按位异或 ...
随机推荐
- 单元测试 Mocking 类库需具备的特性
一个优秀的单元测试 Mocking 类库,需要具备如下几个特性: 易用性:有非常明确的 API ,易于使用并易于记忆. 健壮性:行为结果始终一致,并保持准确. 帮助性:当程序出错时,给出尽可能明确的原 ...
- C语言 线性表 双向链式结构 实现
一个双向链式结构实现的线性表 duList (GCC编译). /** * @brief 线性表双向链表结构 * @author wid * @date 2013-10-28 * * @note 若代码 ...
- MySql和SQL Server数据类型 对比
My Sql 数据类型 SQL Server 数据类型 Yes/No bit Smallint(字节型) tinyint Integer(长整型) int Real(单精度浮点型) real F ...
- [51单片机] EEPROM AT24c02 [存储\读取一个字节]
/*----------------------------------------------- 名称:IIC协议 EEPROM24c02 存数读取数据 内容:此程序用于检测EEPROM性能,测试方 ...
- atitit.条形码的原理与生成总结java Barcode4j barcode o5
atitit.条形码的原理与生成总结java Barcode4j barcode o5 条形码类库使用报告Barcode4j, ZXing 1 使用成果图片 1 条形码标准code 128和code ...
- paip.不同目录结构哈的文件批量比较
paip.不同目录结构哈的文件批量比较 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net/att ...
- 利用jsoup爬虫工具,爬取数据,并利用excel导出
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.FileInputStream; i ...
- 从零开始学Bootstrap(3)
首先让我们回顾一下系列内容. 从零开始学Bootstrap(1)介绍了BootStrap最简单的模板,逐条解释了每行代码的含义. 从零开始学Bootstrap(2)强调了边学边做,通过实际的例子,讲解 ...
- redis 学习指南
一.介绍 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.一个高性能的key-value数据库.并提供多种语言的API.说到Key-Value数据库NoSQL数 ...
- quartzScheduler_Worker-1] but has failed to stop it. This is very likely to create a memory leak解决
01-Jul-2016 07:24:20.218 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 80 ...