# How to change a column name in SQL?

**URL:** <https://forum.inductiveautomation.com/t/how-to-change-a-column-name-in-sql/57464>\
**Category:** Ignition\
**Created:** [March 22, 2022, 3:51pm UTC](https://forum.inductiveautomation.com/t/how-to-change-a-column-name-in-sql/57464 "2022-03-22T15:51:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 22, 2022, 3:51pm UTC](https://forum.inductiveautomation.com/t/how-to-change-a-column-name-in-sql/57464/1 "2022-03-22T15:51:24Z")

</div>

```auto
ALTER TABLE mytable
RENAME COLUMN "oldName" TO "newName";

```

errors out

Someone named a column Date, and it is giving me a bunch of issues.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 22, 2022, 3:53pm UTC](https://forum.inductiveautomation.com/t/how-to-change-a-column-name-in-sql/57464/2 "2022-03-22T15:53:34Z")

</div>

That looks about right. But check your syntax against the documentation for your brand of DB.  
Also, you might not have permission. What is the actual error?

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 22, 2022, 3:55pm UTC](https://forum.inductiveautomation.com/t/how-to-change-a-column-name-in-sql/57464/3 "2022-03-22T15:55:23Z")

</div>

Incorrect syntax near ‘RENAME’.

I am using Microsoft SQL, SQL Bridge module.

I haven’t found keyword ‘rename’ in the W3schools SQL section.  
In alter table, they don’t show changing the name of a column that I saw

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [March 22, 2022, 3:59pm UTC](https://forum.inductiveautomation.com/t/how-to-change-a-column-name-in-sql/57464/4 "2022-03-22T15:59:39Z")

</div>

```auto
Rename column name in MS SQL Server
The process of renaming column name is MS SQL Server is different when compared to the other databases. In MS SQL Server, you have to use the stored procedure called sp_rename.

Syntax
1
sp_rename 'TableName.OldColumnName', 'New ColumnName', 'COLUMN';
Example:
Write a query to rename the column name “BID” to “BooksID”.

1
sp_rename 'Books.BID', 'BooksID', 'COLUMN';
The resulting output will be the same as that for the above queries. Now, that you have understood how to rename a column name in various databases, let us see how you can rename a table name.

```

---

<div class="post-metadata">

**Author:** ![jonathan.taylor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jonathan.taylor/32/4048_2.png) [@jonathan.taylor](https://forum.inductiveautomation.com/u/jonathan.taylor)\
**Post date:** [March 22, 2022, 4:01pm UTC](https://forum.inductiveautomation.com/t/how-to-change-a-column-name-in-sql/57464/5 "2022-03-22T16:01:25Z")

</div>

More info here:

> **[Rename Columns (Database Engine) - SQL Server](https://docs.microsoft.com/en-us/sql/relational-databases/tables/rename-columns-database-engine?view=sql-server-ver15)**
>
> Rename Columns (Database Engine)

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 22, 2022, 4:02pm UTC](https://forum.inductiveautomation.com/t/how-to-change-a-column-name-in-sql/57464/6 "2022-03-22T16:02:07Z")

</div>

I used this after looking through a ton of stack answers

```auto
EXEC sp_rename 'TableName.OldName', 'NewName', 'COLUMN'

```

---

<div class="post-metadata">

**Author:** ![peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@peter](https://forum.inductiveautomation.com/u/peter)\
**Post date:** [March 22, 2022, 4:03pm UTC](https://forum.inductiveautomation.com/t/how-to-change-a-column-name-in-sql/57464/7 "2022-03-22T16:03:00Z")

</div>

It was probable that the column name of “Date” was upsetting the process (as Date is a type). So a fully qualified name would work

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [March 22, 2022, 4:45pm UTC](https://forum.inductiveautomation.com/t/how-to-change-a-column-name-in-sql/57464/8 "2022-03-22T16:45:08Z")

</div>

Might also be worth adding code to make sure problematic names can’t be used.

---

<div class="post-metadata">

**Author:** ![Tanu\_Rai](https://avatars.discourse-cdn.com/v4/letter/t/a4c791/32.png) [@Tanu\_Rai](https://forum.inductiveautomation.com/u/Tanu_Rai)\
**Post date:** [April 25, 2024, 8:22am UTC](https://forum.inductiveautomation.com/t/how-to-change-a-column-name-in-sql/57464/9 "2024-04-25T08:22:49Z")

</div>

To change a column name in SQL, you can use the following syntax:  
ALTER TABLE mytable  
RENAME COLUMN oldName TO newName;

Make sure to replace `mytable` , `oldName` , and `newName` with the appropriate table name, old column name, and new column name respectively.

For detailed instructions on how to rename a column in SQL, you can refer to this blog: How to rename a column in SQL. It provides step-by-step instructions and additional insights into renaming columns in SQL

> **[How to Change Column Name in SQL?](https://www.edureka.co/blog/rename-column/)**
>
> The RENAME command is used to rename column name in sql. ALTER TABLE TableName RENAME COLUMN OldColumnName TO NewColumnName;

---

<div class="post-metadata">

**Author:** ![Zach\_Larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zach_larson/32/54388_2.png) [@Zach\_Larson](https://forum.inductiveautomation.com/u/Zach_Larson)\
**Post date:** [May 10, 2024, 1:32pm UTC](https://forum.inductiveautomation.com/t/how-to-change-a-column-name-in-sql/57464/10 "2024-05-10T13:32:12Z")

</div>

Gives me an error like incorrect syntax near rename.  
Something is wrong where Rename is not recognized at all as a keyword.

I don't understand why Rename keyword was not recognized.  
I see it used all over and wonder what I did wrong with it.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 10, 2024, 2:17pm UTC](https://forum.inductiveautomation.com/t/how-to-change-a-column-name-in-sql/57464/11 "2024-05-10T14:17:04Z")

</div>

You're using SQL server. It's not MySQL.  
Make sure you're searching for the db you're using, otherwise you'll end up having this problem a lot.

tip: SQL server's language is Transact SQL. Add that or t-sql in your googling.

Second link when searching "sql server rename column":

> **[Rename Columns (Database Engine) - SQL Server](https://learn.microsoft.com/bs-latn-ba/sql/relational-databases/tables/rename-columns-database-engine?view=sql-server-ver15)**
>
> Rename Columns (Database Engine)

The first link is a stackoverflow answer with the exact same procedure call.

@Tanu_Rai You're answering a 2 years old post, and your answer is exactly the code that's in the very first post, tried by the op and that didn't work. It's nice of you to answer, but please pay attention to what you're answering to.
