rename a column name

  • how do i rename a column name using T-SQL?

  • sp_rename [ @objname = ] 'object_name' ,

    [ @newname = ] 'new_name'

    [ , [ @objtype = ] 'object_type' ]

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

    http://www.dkranch.net

  • [Ignore me: too much time on out-of-date servers]

    I think we'll need a better description of what you want to do.

    If you want to change the name of a column for the output of a SELECT statement, you simply:

    SELECT column_name_to_change AS "Changed Column Name"

    If you want to permanently change the name of a column in a specific table via T-SQL, I think you may have to shuffle the data to a temporary table, drop the original table, and recreate it with the new column name.

    Other than for academic purposes, I can't think of a good reason to do this via T-SQL vs. via SQL Enterprise Manager. It may do exactly what I said above behind the scenes, but it maintains all the other settings for your table for you.

    If you need to write code to change the name, I'd love to know why. Perhaps someone here could suggest a better alternative....

    R David Francis

    Edited by - rdfozz on 05/06/2003 10:45:21 AM

    Edited by - rdfozz on 05/06/2003 10:46:24 AM


    R David Francis

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply