January 14, 2015 at 2:47 pm
I've been tasked with migrating half of a database to a new instance. Unfortunately for me, there are over 100 stored procedures that need to be modified. Also unfortunately for me, there was no standardization in how tables were referenced. So you'll see a few different types of references.
database.dbo.table
dbo.table
table
Now, each reference needs to be server.database.schema.table.
I'm trying to come up with a good way to do this. Unfortunately since tables can be referenced differently in each stored procedure, I can't think of a great way to do this.
January 14, 2015 at 2:49 pm
JoshDBGuy (1/14/2015)
I've been tasked with migrating half of a database to a new instance. Unfortunately for me, there are over 100 stored procedures that need to be modified. Also unfortunately for me, there was no standardization in how tables were referenced. So you'll see a few different types of references.database.dbo.table
dbo.table
table
Now, each reference needs to be server.database.schema.table.
I'm trying to come up with a good way to do this. Unfortunately since tables can be referenced differently in each stored procedure, I can't think of a great way to do this.
Instead of renaming all of the tables in the procs, consider creating synonyms named the same as the old table name and pointing to the new. Of course, pray there aren't any collisions built in.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 14, 2015 at 2:57 pm
Sounds a bit funky but I guess it could work. I'd almost rather manually change them though.
January 14, 2015 at 3:02 pm
One way would be to:
right click the database>Tasks>Generate Scripts.
Select the 100 stored procs you need to modify and save it to a file.
Then use a text editor to do a find and replace for tablename, then schema.tablename, etc.
January 14, 2015 at 3:04 pm
JeremyE (1/14/2015)
One way would be to:right click the database>Tasks>Generate Scripts.
Select the 100 stored procs you need to modify and save it to a file.
Then use a text editor to do a find and replace for tablename, then schema.tablename, etc.
Unfortunately that won't be much better than doing it manually line by line. It also has some inherent issues in a few situations that make that solution problematic.
It sounds like a may be going this manually.
Sigh.
January 14, 2015 at 3:41 pm
Not something I've tried, but you could look at Red Gate SQL Dependency Tracker[/url]. It does a pretty good job of finding everything that references a table (or other objects). It'll at least give you a good list to work from. Prompt has a Refactor command that does object renames and tracks down dependencies. It might also be worth a shot. Again, not something I've tried with such an extensive and variable set of requirements.
Another option, look to see if you can use regular expressions and a powershell script to identify and modify the objects. On this, we're officially out of my league. But trying to come up with something other than search & replace, which won't work real well.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
January 14, 2015 at 5:42 pm
So, here's what I'm going to do. Every table has a space or new line before each record. So I'll generate a list of tables and then run a replace using that list in each proc, looking for char(13) + table string or char(10) + table string. I'm going to run a test first as I'm not sure how slow it's going to be.
January 15, 2015 at 2:24 am
Why not just use the tools that MS give you with the SSDT, reverse engineer the database into an SQL DB Project in VS2012 shell (or Vs2010 shell), then use the built in REFACTOR option, which will show you all the changes that are required.
you can also add the DB project to TFS to add a degree of change management control to the whole process.
The best bit is its FREE with SQL Server.
_________________________________________________________________________
SSC Guide to Posting and Best Practices
January 15, 2015 at 2:38 am
Another free option (I have no affiliation) is Apex SQL Refactor.
http://www.apexsql.com/sql_tools_refactor.aspx
Edit: Actually, now I'm not sure if that would do the full 4PN refactoring..but maybe worth a quick look.
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply