Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the type of a column from varchar(30) to varcahar(100)?

I have a table that describes like this:

mysql> describe easy_table;
+---------------------+--------------+------+-----+---------+----------------+
| Field               | Type         | Null | Key | Default | Extra          |
+---------------------+--------------+------+-----+---------+----------------+
| id                  | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| version             | bigint(20)   | NO   |     | NULL    |                |
| account_id          | bigint(20)   | NO   | MUL | NULL    |                |
| city                | varchar(30)  | NO   |     | NULL    |                |
...
| name                | varchar(255) | YES  |     | NULL    |                |
| name_two            | varchar(255) | YES  |     | NULL    |                |
+---------------------+--------------+------+-----+---------+----------------+
13 rows in set (0.03 sec)

I'm trying to make the city varchar bigger to varchar(100) and this line doesn't work

alter table easy_table alter column city varchar(100);

this also doesn't work

alter table easy_table alter column city varchar(100) not null;

I get this error:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(100)' at line 1

like image 291
Mikey Avatar asked May 26 '11 05:05

Mikey


People also ask

How do I change varchar?

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. Let us increase size of product_name from varchar(20) to varchar(255).

How do I change the size of a varchar in SQL Server?

In Microsoft SQL Server Management Studio, you can also right-click a table and select "Design" to open the design view. From here you are presented with a list of each column in the table, with each column's respective data type listed next to it. You can modify the value here.

How do I change the size of a varchar in a table?

You can use the ALTER table command to change the length of a varchar column. You can increase the length of a varchar column to a maximum size of 64,000.


2 Answers

alter table easy_table modify column city varchar(100) not null;
like image 179
ajreal Avatar answered Nov 05 '22 00:11

ajreal


Use the Modify keyword, not Alter

like image 35
john ktejik Avatar answered Nov 05 '22 00:11

john ktejik