Wednesday, February 15, 2012

Export some tables from one DB to another WITHOUT lost of primary key?

Hi,
i am using the enterprise manager of our sql server 2000. i want toexport some (not all) tables from one DB to another one with all thedata inside these tables AND the primary keys. if i do i only receivethe tables with the data but all primary keys and indexes will be lost.
how to do it?
thanks, tobi
Script the tables and indexes and execute them in the new database, and create a linked server between the two and do SELECT INSERT INTO. Hope this helps.|||You should be able to use the DTS Export Wizard. Right-click on a database, All Tasks, Export Data.
Select your source and target server/databases, and select "CopyObjects and Data" instead of the default "Copy Tables and Views".
De-select "Copy All Objects" and click the Select Objects button toselect the tables you want. The option to export primary keys isautomatically selected, but can be modified by de-selecting the "Usedefault options" checkbox.

|||AdamMachanic, thanks for your reply.
in 99% i'll get an error (translated by me from german ;):
"[microsoft][odbc sql server driver][sql server]the windows nt-user orthe -group "servername\username" where not found. please check thename."
whats wrong with this?
|||In the DTS Wizard, you need to uncheck 'Use default options', click Options and uncheck both 'Copy database users and roles' and 'Copy object level permissions'.
Unless the Users exist on both SQL Servers, this will generate errors. Objects such as PKs, FKs, Tables, SPs etc will usually copy fine, but Users will not.|||thanks!!! it worked finally!
|||hi,
it worked for a while...but now i have some big trouble with it.
if i do the same steps today:

-"CopyObjects and Data"
-De-select "Copy All Objects" and click the Select Objects button toselect the tables i want.
-uncheck 'Usedefault options', click Options and uncheck both 'Copy database usersand roles' and 'Copy object level permissions'.
all data will be overwritten on the destination DB. i tried thisseveral times. even in the overview (the last step) it only show"Tables" at the end of the overview, not the table-names to copy.
i get mad on this!
isnt there an option in the dts wizard to generate in sql scripts so ican check what it will do before executing it? (like mysql tools do)

|||yesterday again i tried to export some tables from the live DB to my development DB and again i had this problem. is there a known bug with enterprise manager? maybe someone could give me a step by step tut about how to do this. i get mad on this DTS stuff - in mysql this all is so easy.

No comments:

Post a Comment