views:

122

answers:

2

I have a database in which the main table has a really badly named primary key field which I want to rename. This primary key field is referenced by about 20 other tables and about 15 stored procedures.

What is the easiest way to rename this field everywhere it is referenced throughout the database?

+4  A: 

Database refactoring tools exist to perform exactly the kind of operation you require. Just google for 'database refactoring tools' and pick something that will work with your particular brand of database. DB Deploy is an example of such a tool http://dbdeploy.com/ .

If for some reason you wanted to do this manually and you werent dealing with a huge database, I would probably make a text export of the database (ddl and data) and then get busy with find & replace.

edit: Additionally Redgate's (http://www.red-gate.com/) software is very highly rated but costs money. Personally I think their products are excellent and worth every cent considering the time they can save.

Alex
A: 

If it was me, I'd do it manaully using Managment Studio; Select the database, and right click to get Tasks-->Generate Scripts and select all objects in the database to export the DDL into a new query window, or editor of your choice, and the use your 'find' command to find each instance where the key exists, and then make the corresponding change using management studio directly to the database.

Make sure you backup you have a backup database just in case.

EJB