How to revert New_Column_Name to Old_Column _Name ?

  • Hello Everyone,

    could anyone please help me in finding out a solution on how :

    To change the Column name to the old one?

    1. Selecting a Column name from a table (using sys tables) and storing it in a Variable.

    2. Converting it into All Upper Case

    3. Series of Alter Table SQLs are executed where keys are dropped and created etc

    4. And at last, I need to revert the changes made to the Column Name i.e to rename it as before.

    I need help in the last step. Is there anyway to perform it using sys tables or others ?

    Your help is appreciated !

    Thanks

    Devesh

  • Does Case matter in SQL Server?

    Anyways, you can rename the column as follows:

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

    Vinu Vijayan

    For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden[/url] 😉

  • It's good business to provide the schema name as well to avoid any issues with scope where default schema names can get involved.

    Also, do not provide square brackets in the "new name" string otherwise they will become part of the name.

    EXEC sys.sp_rename

    @objname = N'[SchemaName].[TableName].[OldColumnName]', -- provide schema name

    @newname = 'NewColumnName', -- no square brackets unless you want them in the name

    @objtype = 'COLUMN';

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

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

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