1,105,271 Community Members

rename column

Member Avatar
davy_yg
Veteran Poster
1,115 posts since May 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 1 [?]
 
0
 

Hello,

What's the mysql syntax to rename column in a table?

I try this:

 ALTER TABLE static_content RENAME COLUMN title TO shorttext 

MySQL said: Documentation

#1064 - 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 'COLUMN title TO shorttext' at line 1 
Member Avatar
pritaeas
mod_pritaeas
11,301 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,833 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
1
 

http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

RENAME is for tables.

ALTER TABLE static_content CHANGE COLUMN title shorttext VARCHAR(255)

Adjust the column type accordingly.

Member Avatar
ling_tj
Newbie Poster
12 posts since Dec 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

http://www.techonthenet.com/sql/tables/alter_table.php

ALTER TABLE table_name
RENAME COLUMN old_name to new_name;

Member Avatar
anas.man
Newbie Poster
18 posts since Dec 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
-1
 

alter table <tablename> rename column <oldname> to <newname>

Ex : ALTER TABLE emp RENAME COLUMN emp_name to employee_name;

Member Avatar
pritaeas
mod_pritaeas
11,301 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,833 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
1
 

@ling_tj, @anas.man: RENAME COLUMN is Oracle syntax, not MySQL.

Member Avatar
ugi.nagesh
Newbie Poster
14 posts since Nov 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

To rename a column called "Column_Old" to "Column_New" in the table named "customer":

mysql> alter table customer change Column_Old Column_New int(3) unsigned;

So, when renaming a column, we need to provide the old column name first, then after the new column name.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article