How do I rename column in w3schools sql?

alter, sql

Solution

You can try this to rename the column in SQL Server:-

sp_RENAME 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN'

sp_rename automatically renames the associated index whenever a PRIMARY KEY or UNIQUE constraint is renamed. If a renamed index is tied to a PRIMARY KEY constraint, the PRIMARY KEY constraint is also automatically renamed by sp_rename. sp_rename can be used to rename primary and secondary XML indexes.

For MYSQL try this:-

ALTER TABLE table_name CHANGE [COLUMN] old_col_name new_col_name

Problem

I am trying to rename a column name in w3schools website ``` ALTER TABLE customers RENAME COLUMN contactname to new_name; ``` However, the above code throws syntax error. What am I doing wrong?

Original source