Faisal Sajjad
Faisal Sajjad

Reputation: 239

Rename Column name in sql server 2008

How to change column name to a new name.

eg: Column name is "Sr.No." I want to change it to "ID"

i used

sp_RENAME 'Matrix.Sr.No.','ID','COLUMN';

but it gives me error.

Msg 15253, Level 11, State 1, Procedure sp_rename, Line 105
Syntax error parsing SQL identifier 'Matrix.Sr.No.'.

Upvotes: 2

Views: 13738

Answers (2)

nrsharma
nrsharma

Reputation: 2562

Try this

EXEC sp_rename 
    @objname = 'table_name.old_column_name', 
    @newname = 'new_column_name', 
    @objtype = 'COLUMN'

Upvotes: 3

Andomar
Andomar

Reputation: 238048

Matrix.Sr.No means the No column in the Sr table of the Matrix schema in the current database. Try escaping the name:

sp_RENAME 'Matrix.[Sr.No.]','ID','COLUMN';

Upvotes: 4

Related Questions