Step 1: Go to the Databases -> Tables menu and expand it. The following steps are used to rename a table using Object Explorer: SSMS is a GUI tool that allows us to change the table name in the following ways: We can verify whether the table is renamed or not by executing the SELECT statement: SQL Server Management Studio (SSMS) However, the table is renamed successfully. We will get this message because while renaming a table, SQL Server does not automatically change the name of any references associated with that table. The following syntax is used to rename the table:ĮXEC sp_rename 'employee', 'employee_info' Įxecuting this statement, SQL Server shows the following message: The user-created object can be a table or column. SQL Server provides a standard stored procedure called SP_RENAME for renaming the user-created object in the current database. Existing queries, views, user-defined functions, stored procedures, or programs that refer to the table will become invalid due to the name change. We must have very careful before changing the table name. We can change the table name in SQL Server in 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 table.įor example, if we want to change the table name that is also referenced in a trigger, it is required to modify the trigger to reflect the new table name. SQL Server has some restrictions while renaming the table because when we rename a table, it does not imply that all references to that table will be renamed as well. It must ensure that we have ALTER permission on the object before changing the table's name. However, it has a stored procedure named sp_rename that enables us to rename a table. SQL Server does not provide any command to change the table name directly. When the table name is no longer relevant or no longer serves the purpose of creation, we can change it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |