Created
August 31, 2016 15:52
-
-
Save mpstenson/e774132238e357c83d3625201a2a79ce to your computer and use it in GitHub Desktop.
Resize Column Based On Content (for mysql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET @column_name = 'Custom2'; | |
select @column_name; | |
SET @width_query = CONCAT('SET @max_width = (SELECT CHAR_LENGTH(' , @column_name , ') AS mlen FROM `HS_Request` ORDER BY mlen DESC LIMIT 1)+10;'); | |
PREPARE stmt FROM @width_query; | |
EXECUTE stmt; | |
DEALLOCATE PREPARE stmt; | |
SET @query = CONCAT('ALTER TABLE HS_Request MODIFY ', @column_name, ' VARCHAR(', @max_width, ');'); | |
PREPARE stmt FROM @query; | |
EXECUTE stmt; | |
DEALLOCATE PREPARE stmt; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment