none
how to rename column name of a table using sql server command

    Question

  • dear sir plz tell us how to change my column name permanently using sql command???

    note: I want to run it on sql server 2005


    Today is the Great day

    • Moved by CoolDadTxMVP Monday, February 27, 2012 10:59 PM SQL related (From:Visual C# IDE)
    Monday, February 27, 2012 8:01 PM

Answers

  • Use SP_RENAME

    http://msdn.microsoft.com/en-us/library/ms188351.aspx


    Javier Villegas | @javier_villhttp://sql-javier-villegas.blogspot.com/

    Please click "Propose As Answer" if a post solves your problem or "Vote As Helpful" if a post has been useful to you

    • Proposed as answer by Naomi N Tuesday, February 28, 2012 3:17 AM
    • Marked as answer by amber zhangModerator Monday, March 05, 2012 9:29 AM
    Tuesday, February 28, 2012 12:42 AM
  • Hi Ankit,

    If you want to re-name the column name in a table of SQL Server database.

    Please use the below command:

     

    USE satish;

    GO

    EXEC sp_rename 'dbo.Persons.Address', 'Full_Address', 'COLUMN';

    GO

    After Successful Execution of above command, the output should be like below

    Caution: Changing any part of an object name could break scripts and stored procedures.

    Hence Please be carefull, that you are taking care on the new column on Views, functions, storeprocures e.t.c to avoid failures..

    Thanks,


    Thanks, Satish Kumar. Please mark as this post as answered if my anser helps you to resolves your issue :)

    • Proposed as answer by Naomi N Tuesday, February 28, 2012 3:17 AM
    • Marked as answer by amber zhangModerator Monday, March 05, 2012 9:29 AM
    Tuesday, February 28, 2012 2:57 AM

All replies

  • Hi,

    use the following SQL command

    RENAME old_table_name TO new_table_name;

    Best Regards. When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer. This helps us build a healthy and positive community.

    Monday, February 27, 2012 9:15 PM
  • EXEC sp_rename 'Schema.tablename.columnname', 'new column name', 'COLUMN';
    • Proposed as answer by Naomi N Tuesday, February 28, 2012 3:17 AM
    Monday, February 27, 2012 11:04 PM
  • Use SP_RENAME

    http://msdn.microsoft.com/en-us/library/ms188351.aspx


    Javier Villegas | @javier_villhttp://sql-javier-villegas.blogspot.com/

    Please click "Propose As Answer" if a post solves your problem or "Vote As Helpful" if a post has been useful to you

    • Proposed as answer by Naomi N Tuesday, February 28, 2012 3:17 AM
    • Marked as answer by amber zhangModerator Monday, March 05, 2012 9:29 AM
    Tuesday, February 28, 2012 12:42 AM
  • Hi Ankit,

    If you want to re-name the column name in a table of SQL Server database.

    Please use the below command:

     

    USE satish;

    GO

    EXEC sp_rename 'dbo.Persons.Address', 'Full_Address', 'COLUMN';

    GO

    After Successful Execution of above command, the output should be like below

    Caution: Changing any part of an object name could break scripts and stored procedures.

    Hence Please be carefull, that you are taking care on the new column on Views, functions, storeprocures e.t.c to avoid failures..

    Thanks,


    Thanks, Satish Kumar. Please mark as this post as answered if my anser helps you to resolves your issue :)

    • Proposed as answer by Naomi N Tuesday, February 28, 2012 3:17 AM
    • Marked as answer by amber zhangModerator Monday, March 05, 2012 9:29 AM
    Tuesday, February 28, 2012 2:57 AM
  • In SQL Server, there is no direct SQL Statments for renaming the column names, or even indexes or tables. It uses a stored procedure "sp_rename" for renaming tables, indexes, columns, alias data types, or Microsoft .NET Framework common language runtime (CLR) user-defined types.

    For renaming column, the generalized syntax will be:

    EXEC sp_rename

        @objname = 'TableName.OldColumnName',

        @newname = 'NewColumnName',

        @objtype = 'COLUMN'

    More details are available here: http://msdn.microsoft.com/en-us/library/ms188351.aspx 


    Vishal Soni

    Tuesday, November 20, 2012 5:50 AM