can I alter a table column name thru TSQL

  • Hi,

    As far as i can see, there is no way to ALTER the "name" of a table column thru TSQL, though it seems that you can do everything else with a column thru the TSQL "ALTER" statement.

    Is there a logical reason for this?Do I have to go to EM and manually change the name of the column that I want to alter?

    Cheers,

    yogiberr

  • sp_rename

  • sp_rename uses utilizes DBCC RENAMECOLUMN. As this command is undocumented, I guess there is no direct way with T-SQL.

    Frank

    http://www.insidesql.de

    http://www.familienzirkus.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • thanks folks,

    So, would I be best to:

    1) use "sp_depends" on the table that I am about to alter (to find out which other db objects the column name-change could affect)

    2) use "sp_rename" to rename the table column.

    3) update all the objects that reference the renamed column.

    Did i understand correctly?

    ta,

    yogiberr

  • Hi

    What I usually do if I'm not sure how to do something in QA is to do what I want to do in EM in a test database and record it all through profiler. You can then pick out the QA commands required.

  • Good tip.

    thanks all.

    yogi

  • I go into EM, make all the changes, choose "Save change script" to capture all the commands, then exit without saving the actual changes.

    Or sometimes I do save the actual changes, but archive the "change script" so I have a history of what was done.

Viewing 7 posts - 1 through 6 (of 6 total)

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