Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Databases»SQL Server»How to Rename a Column in SQL Server

    How to Rename a Column in SQL Server

    By RahulJune 28, 20212 Mins Read

    Database design is the organization of data. A good database design makes it successful. Its recommended to follow a good pattern for the table names and their columns. In some cases, you may be required to rename a column name of the table to maintain a proper architecture and naming pattern. The sp_rename stored procedure is used to rename a column name in a table in MSSQL server database.

    Advertisement

    Syntax:

    The syntax of the sp_rename stored procedure is:

    sp_rename 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN'
    
    Caution: Changing any part of an object name could break scripts and stored procedures. Make sure to update all the required scripts and stored procedures with updated names.

    Rename a Column in SQL Server

    For example, I have a table named Accounts in the MSSQL server database. This table contains a column named “cust_id”. For some reason, we need to rename this column to “customer_id”. See below screenshot:

    Open query windows and execute the following query. Here Test_dbis the database name.

    USE Test_db
    GO
    
    sp_rename 'Accounts.cust_id', 'customer_id' , 'COLUMN'
    GO 
    

    This may show you a warning message with the result, But this will rename the column name successfully. Checked the table structure again, and I found that the column is updated as required.

    Rename table column in SQL Server

    Conclusion

    This tutorial helped you to rename a table column name in the SQL Server database.

    mssql SQL SErver stored procedure
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Backup SQL Server Database

    How to Backup SQL Server Database

    How to Restore SQL Server database

    How To Restore SQL Server Database

    How to Rename SQL Server Database

    How to Rename a SQL Server Database

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Implementing a Linux Server Security Audit: Best Practices and Tools
    • cp Command in Linux (Copy Files Like a Pro)
    • 15 Practical Examples of dd Command in Linux
    • dd Command in Linux (Syntax, Options and Use Cases)
    • Iptables: Common Firewall Rules and Commands
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.