![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
My boss says ok here are 2 sql backups. We think they have the same tables and columns. merge them. this is sqlserver 2008 r2 oh wait here is another database that I think has all the tables and columns so delete all the data in it and then merge the other two databases using the third and use the schema of the third one. help I don't have a clue how to do this. any pointers on info I can find and read up on this or about how to do it and how to track errors? |
#3
| |||
| |||
|
|
sparks (twwhopper (AT) hotmail (DOT) com) writes: My boss says ok here are 2 sql backups. We think they have the same tables and columns. merge them. this is sqlserver 2008 r2 oh wait here is another database that I think has all the tables and columns so delete all the data in it and then merge the other two databases using the third and use the schema of the third one. help I don't have a clue how to do this. any pointers on info I can find and read up on this or about how to do it and how to track errors? It seems that you need to first identify your requirements. You have two or three databases, that you want to "merge", whatever that means. You think that the databases have the same tables and columns. Hm, so what about verifying that first. And then you need to define what you really mean with "merge". |
#4
| |||
| |||
|
|
I asked ok on this merge there are 3 different types of merges that I know of. |
#5
| |||
| |||
|
|
sparks (twwhopper (AT) hotmail (DOT) com) writes: I asked ok on this merge there are 3 different types of merges that I know of. Well, this merge operation sounds a little more complicated that you would do in a source-code control system. Most likely there will be conflicts and a lot decisions to make. Good luck! |
#6
| |||
| |||
|
|
Yes it is way more complicated than I expected. like the main table that has the pk and controls all the data. one have 49 variables while the other has 51. The main table in the new one has 6 variables. the other variables are in 4 other tables AHHHHHH lol On Wed, 21 Mar 2012 23:54:50 +0100, Erland Sommarskog esquel (AT) sommarskog (DOT) se> wrote: sparks (twwhopper (AT) hotmail (DOT) com) writes: I asked ok on this merge there are 3 different types of merges that I know of. Well, this merge operation sounds a little more complicated that you would do in a source-code control system. Most likely there will be conflicts and a lot decisions to make. Good luck! |
#7
| |||
| |||
|
#8
| |||
| |||
|
|
what I have problems with is when you have references in C do I have to delete all the references in the tables, insert the data and then rebuild the references. |
#9
| |||
| |||
|
|
sparks (twwhopper (AT) hotmail (DOT) com) writes: what I have problems with is when you have references in C do I have to delete all the references in the tables, insert the data and then rebuild the references. What references? You mean the foreign key definitions? If you want to perform this operation with no foriegn keys getting in your way, you can say: ALTER TABLE tbl NOCHECK CONSTRAINT constraint_name To do this on all tables, runs this query: SELECT 'ALTER TABLE ' + quotename(s.name) + '.' + quotename(o.name) + ' NOCHECK ' + quotename(fko.name) FROM sys.foreign_keys fk JOIN sys.objects fko ON fk.object_id = fko.object_id JOIN sys.objects o ON o.object_id = fk.parent_object_id JOIN sys.schemas s ON o.schema_id = s.schema_id and then run the result. To enable the constraints again, the command is somewhat funny: ALTER TABLE tbl WITH CHECK CHECK CONSTRAINT constraint_name The extra WITH CHECK is needed to have SQL Server actually validate that the constraints are valid. It goes without saying that you should keep backups so that you can go back if one step of the operation does not complete successfully. |
#10
| |||
| |||
|
|
Thank you for the help. Sorry it too soooo long to get back. I have 3 other projects and have been running in circles. one more thing if you have a column with values such as 1,2,3,4 not I have to replace them with 5,6,7,8 is there a single way to say if 1 replace with 5, if 2 replace with 6 etc I see how on a replace 1 with 5 then another statement replace 2 with 6 but not all at once,can that be done Sure - use a CASE statement: |
![]() |
| Thread Tools | |
| Display Modes | |
| |