![]() ![]() The syntax to change the column name using this approach is:ĮXEC SP_RENAME 'Student.city', 'city_name', 'COLUMN'Īfter executing this script, we will get the following message: We advise you to drop the object and re-create it with the new name rather than using this statement to change the name of stored procedures, triggers, user-defined functions, or views. ![]() Scripts and stored procedures may be broken when we change some portion of an object's name. The user-created object can be a table, column, index, alias data type, etc. SQL Server provides a standard stored procedure called SP_RENAME for changing the name of a user-created object in the current database. We can rename the table columns in SQL Server using mainly two ways: The sys.sql_expression_dependencies can be used for listing all dependencies on the object before changing the name. We must manually modify all objects that belong to the renamed column.įor example, if we want to change the column of a table that is also referenced in a trigger, it is required to modify the trigger for reflecting the new column name as well. SQL Server has some restrictions while changing the column name because when we rename a column, it does not imply that all references to that column will be renamed as well. It must ensure that we have ALTER permission on the object before changing the column's name. We will rename the table columns when the column name is non-meaningful or does not fulfill the purpose of its creation. SQL Server allows us to change the column whenever we need. Next → ← prev Rename Columns in SQL Server ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |