Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - How to increase varchar size of an existing column in a database without breaking existing data?

Tags:

mysql

I have a column that is currently varchar(100) and I want to make it 10000.

is it as simple as

alter table table_name set column col_name varchar (10000); 

I am afraid to corrupt the exiting data. Will I be ok if I run this query? Or should I do I alter the column another way?

Thanks!

like image 719
Genadinik Avatar asked Apr 17 '12 01:04

Genadinik


People also ask

How do you increase the length of a VARCHAR column?

In this case, you need to use ALTER TABLE statement to increase column size. ALTER TABLE table_name MODIFY column_name varchar(new_length); In the above command, you need to specify table_name whose column you want to modify, column_name of column whose length you want to change, and new_length, new size number.

How do I change the size of a VARCHAR in MySQL?

Here is how you do it: ALTER TABLE address MODIFY state VARCHAR(20) ; In generic terms, you use the ALTER TABLE command followed by the table name, then the MODIFY command followed by the column name and new type and size.

What is the max length of VARCHAR in MySQL?

Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.


1 Answers

It's safe to increase the size of your varchar column. You won't corrupt your data.

If it helps your peace of mind, keep in mind, you can always run a database backup before altering your data structures.

By the way, correct syntax is:

ALTER TABLE table_name MODIFY col_name VARCHAR(10000) 

Also, if the column previously allowed/did not allow nulls, you should add the appropriate syntax to the end of the alter table statement, after the column type.

like image 64
Lynn Crumbling Avatar answered Sep 20 '22 06:09

Lynn Crumbling