在VARCHAR修改上强制截断? [英] Force Truncation on VARCHAR modification?
本文介绍了在VARCHAR修改上强制截断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在几列上将VARCHAR限制为255,以便添加索引。
I would like to cap VARCHAR to 255 on a few columns so that I can add an index.
alter table striker modify contacts varchar(255)
当我尝试运行上述命令时,我得到
When I try to run the above command I get
Error Code: 1265. Data truncated for column 'contacts' at row 331 38.969 sec
是否有一种方法可以强制截断列,以便此命令成功缩短VARCHAR?我不在乎缩短列中的数据。
Is there a way to force truncation of the column so that this command successfully shortens the VARCHAR? I don't care about shortening the data in the column.
推荐答案
您可以手动将列截断为255个字符:
You can manually truncate the column at 255 characters:
UPDATE striker
SET contacts = SUBSTR (contacts, 1, 255);
现在,您知道没有值超过255个字符,则执行您在OP中安全地拥有的更改表
语句。
Now, that you know that no value is longer than 255 characters, you perform the alter table
statement you have in the OP safely.
这篇关于在VARCHAR修改上强制截断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文