1

I have a table "Customers" and in this table I can 3 columns (ID, firstName, LastName).

I would like to rename the ID column to be ID_1

It is possible to add the _1 as a prefix?

I been trying to search for this but all the responses and solution that I getting are not accurate.

2
  • do you want change table field name or create an alias? Commented Dec 2, 2015 at 18:47
  • @JuanCarlosOropeza it has to change the filed name. Commented Dec 2, 2015 at 18:50

2 Answers 2

2

To rename a column in table you should use sp_rename stored procedure like this:

EXEC sp_RENAME 'Customers.ID' , 'ID_1', 'COLUMN'
Sign up to request clarification or add additional context in comments.

Comments

1

if you want change the display fieldname use an alias

  SELECT ID as ID_1, firstName, LastName
  FROM Customers

To rename the field on the table you use the script sp_rename

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


 EXEC sp_RENAME 'Customers.[ID]' , '[ID_1]', 'COLUMN'

4 Comments

A small question, what if I want to have back the name, it is possible to perform the same step? executing the same script?
but when I try to use the script again I get the error (Either the parameter objname is ambiguous or the claimed objtype (COLUMN) is wrong.)
Yes but invert the parametes EXEC sp_RENAME 'Customers.[ID_1]' , '[ID]', 'COLUMN'
Thanks I had to add a double quotes "" in the object name. Thanks a lot guys!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.