Possible consequences of increasing varchar length in MySql?

别来无恙 提交于 2019-11-28 08:41:11

问题


I'm using an old table, which has a varchar(40) field in it. I want it to be possible to insert more characters in that field, so I want to increase the length of it.
Are there possible negative consequences I should think of before increasing the length?


回答1:


Increasing should typically not cause issues, it is the decreasing that can cause problems.




回答2:


Changing the declared size of a varchar field should not require the existing data to be modified.

Note that changing the size of char or number field will require MySQL to update every affected value to the new type. Changing such fields or adding columns may result in the DBMS having to rewrite the entire table in order to accomodate a larger row size depending on whether there is any redundant space at the row level. This can take some time on a large table.

Make sure that you update any other tables which join to this column too!

HTH

C.




回答3:


If you have set the length of 40 but if you try insert more chars, then all will be rejected resulting in empty field value. You should provide the upper length value that you are expected to enter for that field.



来源:https://stackoverflow.com/questions/2100254/possible-consequences-of-increasing-varchar-length-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!