问题描述
错误代码:1406.列的数据太长
Error Code: 1406. Data too long for column
CREATE TABLE `TEST`
(
`idTEST` INT NOT NULL ,
`TESTcol` VARCHAR(45) NULL ,
PRIMARY KEY (`idTEST`)
);
现在插入一些值
INSERT INTO TEST
VALUES
(
1,
'Vikas'
)
select
SELECT * FROM TEST;
插入超过长度
INSERT INTO TEST
VALUES
(
2,
'Vikas Kumar Gupta Kratika Shukla Kritika Shukla'
)
如果我们select length
SELECT LENGTH('Vikas Kumar Gupta Kratika Shukla Kritika Shukla')
'47'
它显示错误信息
错误代码:1406.列的数据太长
但我的期望是,我想在表格中至少插入前 45 个字符
But what is my expectation is, I want to insert at least first 45 characters in Table
如果问题不清楚,请告诉我.
please let me know if the question is not clear.
我知道这个错误的原因.我试图插入超过数据类型长度的值.
I know the cause of this error. I am trying to insert values more than the length of datatype.
我想要在 MySQL 中的解决方案,因为它可以在 MS SQL 中实现.所以我希望它也能在 MySQL 中.
I want solution in MySQL as It is possible in MS SQL. So I hope it would also be in MySQL.
推荐答案
MySQL 将截断任何超过指定列宽的插入值.
MySQL will truncate any insert value that exceeds the specified column width.
要做到这一点,请尝试将您的 SQL 模式 切换为不使用 STRICT.
to make this without error try switch your SQL mode to not use STRICT.
Mysql 参考手册
改变模式
这可以通过两种方式完成:
This can be done in two ways:
- 在 MySQL 安装目录中打开您的
my.ini(Windows) 或my.cnf(Unix) 文件,并查找文本sql-mode".
- Open your
my.ini(Windows) ormy.cnf(Unix) file within the MySQL installation directory, and look for the text "sql-mode".
查找:
代码:
# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
替换为:
代码:
# Set the SQL mode to strict
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
或
- 您可以在数据库管理工具(例如 phpMyAdmin)中运行 SQL 查询:
代码:
SET @@global.sql_mode= '';
这篇关于错误代码:1406.列的数据太长 - MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)