ALTER TABLE mytable
RENAME COLUMN "oldName" TO "newName";
errors out
Someone named a column Date, and it is giving me a bunch of issues.
ALTER TABLE mytable
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?
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.
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.
More info here:
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
Might also be worth adding code to make sure problematic names canāt be used.