Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql change column details

I am trying to redefine the number of varchars a column can have (in a MySQL db).

I am doing

alter table obj_details IMG_SRC IMG_SRC varchar(180);

I want to change the number of characters that can be used in the column IMG_SRC to 180 (it is currently 100). But I get an error saying that I should check the syntax near IMG_SRC IMG_SRC varchar(180).

like image 362
Ankur Avatar asked May 14 '10 07:05

Ankur


People also ask

How do I change column information in MySQL?

To change a column name, enter the following statement in your MySQL shell: ALTER TABLE table_name RENAME COLUMN old_column_name TO new_column_name; Replace table_name , old_column_name , and new_column_name with your table and column names.

How do I change the properties of a column in SQL?

In Object Explorer, right-click the table with columns for which you want to change the scale and select Design. Select the column for which you want to modify the data type. In the Column Properties tab, select the grid cell for the Data Type property and choose a new data type from the drop-down list.

How do I change text in a column in MySQL?

Use the MySQL REPLACE() function to replace a substring (i.e. words, a character, etc.) with another substring and return the changed string.


2 Answers

Why did you write IMG_SRC twice? You want:

ALTER TABLE obj_details MODIFY IMG_SRC varchar(180);

(For what it's worth the COLUMN in MODIFY COLUMN is optional, see here.)

like image 169
Dominic Rodger Avatar answered Nov 15 '22 20:11

Dominic Rodger


You're missing MODIFY COLUMN, and you're specifying IMG_SRC twice for some reason.

Try this instead,

ALTER TABLE `obj_details` MODIFY COLUMN `IMG_SRC` VARCHAR(180);
like image 37
Rich Adams Avatar answered Nov 15 '22 20:11

Rich Adams