what is the easiest way to change column name

Database
Enthusiast

what is the easiest way to change column name

If i want to change column name from 'ABC' to 'ABCD', what is the easiest way to do it. and if the column is one of the primary index, how could i do it?
4 REPLIES
Enthusiast

Re: what is the easiest way to change column name

you can do an

ALTER TABLE mytbl RENAME COLUMN oldnme TO newnme;

However there are restrictions, like you can't rename a column if it's part of an index (for PI you will have to drop and recreate the table, for SI, drop indexes and then rename, create the SI again ...)

For the complete list of restrictions, lookup the "Renaming Table Columns" section in data definitions manual.
Enthusiast

Re: what is the easiest way to change column name

Thank you. That works fine.

Re: what is the easiest way to change column name

Just to clarify, the word "column" should not be in the statement.

Re: what is the easiest way to change column name

ALTER TABLE mytbl RENAME COLUMN oldnme TO newnme;

not use column keyword here