Forum Moderators: open
I have a text column in a database table. Can anyone tell me the MySQL command that would allow me to cut the number of characters to a maximum of 255?
The table is quite large and has many pre-existing entries which have column entries of way over 255 characters so i do need to to have the column as a 'text' one rather than 'varchar', however for certain recent posts I need to limit the length to 255 characters.
I've tried loads of searches but can't find the mysql code that allows me to do this, so if anyone can help me I'd be really grateful.
thanks!
- Easiest, change the current field to varchar(255). This, of course, will truncate all your old data.
- Add a new varchar(255) field, and direct all new inserts to it. On reading, you will have to add some programming to get the new data as well as the old, not sure how you'd do this - maybe do it by date of the change or whether one or the other is blank/null.
- If you're a programmer, this is probably easier than truncating your data. Add programming in your input to truncate the incoming text to 255 characters.
Overall, I would say the first option may be best as it will reduce the size of a large table by quite a bit, but you will truncate existing data which may not be an option.
Its really a one off command I need which can trim some (but only some) of the data. So somethig like:
trim 'column' to maximum 255 characters WHERE topic_id > 1179
Truncating old data (either by changing column structure or via programming) isn't really an option as the old data is held within various language tags and deleting those would be a disaster.
Is there any way to do this in MySQL?
thanks a lot!