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
 General SQL Server Forums
 New to SQL Server Programming
 HOw to import an updted tbl form one dB to another

Author  Topic 

Pasi
Posting Yak Master

166 Posts

Posted - 2014-01-13 : 19:14:24
HI,

I have a table called diagnosis_status in my TestdB environment and want to import the same table into my production (PROD) dB.

This table also exist in PROD but I have update the one in Test dB and want to import the updated one into PROD?

is there such copy/paste tools? I don't see it in my management studio?

Thanks!
Pasi

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-14 : 04:18:28
If your attempt is to replace the production tables data with testdb table then first truncate data from production using TRUNCATE TABLE and then using export import wizard transfer data from testdb table to production.
You can also script out inserts from testdb using generate scripts wizard in SQL management studio and then apply it to production db.


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Pasi
Posting Yak Master

166 Posts

Posted - 2014-01-14 : 11:16:14
thanks but I have not done truncating? Not sure how its done and don't want to do anything wrong since its production. what does it do? I am only trying to update the same table in test dB in PROD so I thought may be I just replace the current table in PROD with the table with in Test.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2014-01-15 : 04:20:01
maybe take a copy of the PROD table / data first - "just in case" ?

SELECT *
INTO dbo.TEMP_diagnosis_status_20140115
FROM dbo.diagnosis_status

then you can use that to recover the PROD table's data exactly as it was if something goes wrong.

Make sure people do not update diagnosis_status on PROD after you take this copy, until you have finished, and tested, your "import".

You might be able to do this:

BEGIN TRANSACTION
GO
TRUNCATE TABLE dbo.diagnosis_status
GO
INSERT INTO dbo.diagnosis_status
SELECT *
FROM TestDB.dbo.diagnosis_status
GO
-- If NO errors:
COMMIT
-- Or if there ARE errors:
ROLLBACK

If Test DB is on another server, AND there is a linked server to use to connect to it then you can do this instead:

FROM MyLinkedTestServer.TestDB.dbo.diagnosis_status

if there is NO linked server either create one!! or do as Visakh says and use Export/Import wizard.

NOTE: If the DDL Structure of the table has changed in TEST then it is more complicated. You would need to rollout a "patch" to the structure of the PROD DB, and then copy the data across. It is also possible that all applications that use the database would need to be, simultaneously, updated to become "aware" of the structure change.

Final point: the data in your diagnosis_status table has presumably ONLY changed on TEST DB and has NOT changed on PROD? Otherwise any changes to the data, made on PROD, will be lost when you copy over from TEST. If you need "some & some" then you will need to build a selective import from TEST. If that's the case ask and we can help with that.

Don't forget to

DROP TABLE dbo.TEMP_diagnosis_status_20140115

in a week or two's time if all goes well (That's why I use the "TEMP_" prefix, and the Date suffix, so that when looking at the database in a month's time you/Admin can say "That can't be required anymore" and drop it. All such tables will be grouped alphabetically under "TEMP_", and the Date tells you WHEN it was created, and thus how Old/Stale it is now.)
Go to Top of Page

Pasi
Posting Yak Master

166 Posts

Posted - 2014-01-15 : 12:41:20
Wow Kristen mate, this was awesome explanation! thank you! Although I have not done this I will approach this carefully. thanks again for your brilliant post!
Good daay!
Go to Top of Page
   

- Advertisement -