how to rename column name with T-SQL

Solution 1:

I don't really understand how your table is set up - ie. the table name, the column name etc - so this is an example of how the proc works for column renames:

If I had a table like this:

CREATE TABLE [dbo].[Company](
[ID] [int],
[CompanyName] [varchar](20)
)

and wanted to change the [CompanyName] column, this is the command:

EXEC sys.sp_rename 
    @objname = N'dbo.Company.CompanyName', 
    @newname = 'Name', 
    @objtype = 'COLUMN'

I suspect that your first argument is not correct.

From the documentation (sp_rename (Transact-SQL))

If the object to be renamed is a column in a table, object_name must be in the form table.column or schema.table.column. If the object to be renamed is an index, object_name must be in the form table.index or schema.table.index

Solution 2:

You can also change the column name by right-clicking on the Column name and choosing 'rename' option in the Object Explorer.