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
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).
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.
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.
alter table easy_table modify column city varchar(100) not null;
Use the Modify keyword, not Alter
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