/  Technology   /  How to Change Column Size in MySQL?

How to Change Column Size in MySQL?

 

It is sometimes necessary to change the column size or field length in MySQL. This article describes how to change the size of a column in MySQL. These commands can be used to increase or decrease column size in MySQL.

How to Change Column Size in MySQL

Here is how you can increase the length of a field in MySQL. Imagine you have a VARCHAR column with a length of 20 and wish to increase its length to 255.

 

To increase the column size in this case, you must use the ALTER TABLE statement.

Syntax:

#start
ALTER TABLE table_name
MODIFY column_name
varchar(new_length);
#end

This command requires you to specify the table name whose column you wish to modify, the column name of the column whose length you wish to change, and the new_length, the new size.

Example:

 

1.Create Table

# start
create table sales(
create table sales(
id int,
product_name varchar(20),
order_date date
);
#end
  1. Describe Table
#start
describe sales;
#end

Output:

Let us increase the size of product_name from varchar(20) to varchar(255).

#start
alter table sales
modify product_name varchar(255);
#end

Output:

#start
describe sales;
#end

Output:

 

Leave a comment