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!
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With