Gunter 	Wesley
Gunter Wesley

Reputation: 21

SQL Server objects in database

Well, I haven't found exact what I need in similar questions...

What is the quickest way for renaming object/s in DB?

Bulk renaming while keeping dependencies?

Any tips are welcome.

Upvotes: 2

Views: 103

Answers (2)

Milica Medic Kiralj
Milica Medic Kiralj

Reputation: 3780

You can of course use the sp_rename procedure to rename an object, however you'll need to find all objects that an object depends on, and all objects that depend on an object and change them to reflect the changes. You also need to change code of all external applications, if any that access that table.

If you want to rename stored procedure or a view the sp_rename is not advisable.

To rename a view

While you can use sp_rename to change the name of the view, we recommend that you delete the existing view and then re-create it with the new name.

The quickest way to rename an object without breaking dependencies is to use the third party tool. One of them is ApexSQL Refactor. You can find the whole procedure for renaming any object in the article: SQL database refactoring techniques – Rename method

Disclaimer: I work for ApexSQL as a Support Engineer

Hope this helps

Upvotes: 1

Patrick Hofman
Patrick Hofman

Reputation: 157116

With sp_rename you can rename object in SQL Server but you are right, they will break dependencies, so that is not the way to go...

There are several (non-free) tools that can do this, and since they are on the market, I think they are there to solve a problem you can't solve yourself (instead of getting a database script and use Rename all).

A tool that you could use is RedGate SQL Refactor.

Upvotes: 2

Related Questions