How to rename columns of a sql table using a query

2

Even if you miss an error, make the changes.

The question is simple, instead of modifying the table from the designer, I want to do it from a query. I have found how to modify the type, the description ... except the name!

I have tried sp_rename and do not recognize the tables. Commands like Rename, ... are not supported.

I have no useful code to show, because I have not achieved anything, I just have the table on one side and I want to put new names to the columns.

I could do it by hand, but I'm curious: P

EXEC sp_RENAME 'OOEMSG.OEUSBY', 'aaaaa', 'COLUMN'
  

The parameter @objname is ambiguous or the value of @objtype (COLUMN) is not correct.

    
asked by GDP 07.07.2017 в 09:23
source

1 answer

6

I just did a quick search and I found this response from OS in English where you use the command " sp_rename "

EXEC sp_RENAME 'TableName.OldColumnName' , 'NewColumnName', 'COLUMN'

Remember to use single quotes to include values.

See: SQL SERVER - How to Rename a Column Name or Table Name

and also: SQL SERVER - Alter table statement

Edit:

Try the following query, adding parentheses to both the table and the first parameter column, as follows:

EXEC sp_RENAME '[TableName].[OldColumnName]' , 'NewColumnName', 'COLUMN'
    
answered by 07.07.2017 / 09:30
source