How To Modify the Existing Column

  • Hello All,

       I want to modify the existing column name from my table through T-sql. without loosing my data.

     

    Plz help me out.

     

  • USE sp_rename built in function.

    Ex:

    USE AdventureWorks;GOEXEC sp_rename 'Sales.SalesTerritory.TerritoryID', 'TerrID', 'COLUMN';GO
     
  • Yep... then make sure that you rename the column in every stored procedure, view, UDF, foreign key, etc, that uses that column in all databases...

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Thx For your usefull guideline. It worked.

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

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