How to rename a table and all its references in SQL Server ? Programmatically will be preferred , but any tools also will do equally good.
References include stored procedures, view and other database objects as well.
Objects which depend on the table as well as objects on which the table depends.
Too rename a table use the ALTER
function
ALTER TABLE table_name
RENAME TO new_table_name;
To rename a view use the System Stored Procedure sp_rename
EXEC sp_rename 'dbo.view_name', 'new_view_name'
The same goes for renaming Stored Procedures
EXEC sp_rename 'sp_stored_procedure_name', 'sp_new_stored_procedure_name'
We can do using SQL Server Data Tools and Visual Studio refactoring feature.(https://msdn.microsoft.com/en-US/library/aa833262(v=vs.80).aspx)
Or by using SQL Server Data Tools (https://msdn.microsoft.com/en-us/library/hh272704(v=vs.103).aspx)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With