Xion
Xion

Reputation: 318

Dynamically increase SQL Column length

Is there a way to dynamically increase Database Column length if an incoming data is larger than the length specified. Which database software can handle this ? Or is it something that needs to be handled by the application that inserts this data into the database ?

Upvotes: 0

Views: 1657

Answers (1)

DimoMohit
DimoMohit

Reputation: 722

I support @Ed Mendez and @HLGEM that you shouldn't do this but still if you want to do this then you should write a Procedure to do this. You should check the column size with SELECT COLUMN_NAME, CHARACTER_MAXIMUM_LENGTH FROM information_schema.columns WHERE table_schema = DATABASE() AND -- name of your database table_name = 'table_name' AND -- name of your table column_name = 'name_of_column' -- name of the column in IF condition and then ALTER the table with ALTER Query. But while checking again in Procedure you will have to take care of input size. So better you can go for VARCHAR. If still you are unable to do please give the demo of your column I'll write the procedure code. Hope this help you.

Upvotes: 1

Related Questions