How to change a column name in SQL?

RENAME COLUMN "oldName" TO "newName";

errors out

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

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?

1 Like

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

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.

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

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.

More info here:

1 Like

I used this after looking through a ton of stack answers

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

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

1 Like

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