Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Alter Table Based on Template Table

Author  Topic 

reepcore
Starting Member

3 Posts

Posted - 2015-05-06 : 03:46:14
I have two databases with identical tables, however the actual table structures are slightly different.

Does anyone have any sample T-SQL that can loop through all columns in a 'template' table and update another 'target' table to match? All of the column properties should be identical.

There is no consideration required for the data that exists in the 'target' table.

Thanks in advance.

Kristen
Test

22859 Posts

Posted - 2015-05-06 : 06:12:19
Red Gate have excellent tools which will do that. For example you have a Production system and then make all sorts of changes in a Development system. You can point Red Gate at the Production and Development databases and it will figure out the differences and make a script which will "upgrade" the Production Database.

www.red-gate.com
Go to Top of Page

reepcore
Starting Member

3 Posts

Posted - 2015-05-15 : 03:34:16
That Kristen.

Unfortunately there is no way that I am going to be able to use this software as we cannot host it on our servers, and we need to do this on multiple db servers each with disparate DBs.

Any other suggestions would be greatly appreciated.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2015-05-15 : 04:28:31
I thought you could run it (i.e. RedGate APP) on your PC and "point" it at the DBs? (Presumably that's how you access the DBs anyway? If you have to use Terminal Services to reach each one, for example, then that's a bit different ... and a complete PITA! We don't take on clients that won't grant us direct access to their DBs ... takes far too long to do anything working through a letterbox ...)

Second suggestion would be to script the whole database (not including data), download the generated scripts back to your PC and create a matching database locally. A copy of SQL Express (or whatever its called now!) would do. Its a free download. Then point RedGate or similar at those local DBs.

There are scripts in the public domain that will do a similar comparison job to RedGate, but I have no idea how well they work ... RedGate make their living from that sort of thing, so I presume they are rock solid. I have colleagues who deploy their stuff using RedGate, but in my bit of the company we build SQL scripts as we change things and deploy form that, so I don't have first hand experience.
Go to Top of Page
   

- Advertisement -