Transfer data from one database to another without identities but keep the relation b/w PK and Foreign key

Hi,
I need to transfer data from one database to another database (both are identical databases). 
1. Not transferring identity columns (primary keys). the destination table might have the same key.
2. keep the PK's and FK's relation b/w parent and child table
3. I have 4 levels 
Example: tableA (col1 int identity(1,1) , col2, col3)
tableB (col1 int identity(1,1) ,
col2 , col3) -- col2 has the foreign key relation with tableA.col1
tableC (col1 int identity(1,1) ,
col2, col3) -- col2  has the foreign key relation with tableB.col1
tableD (col1 int identity(1,1) , col2, col3) -- col2  has the foreign key relation with tableC.col1
please advise me.
Thanks in advance

Try the below:
/********************************SAMPLE TARGET***************************************************************/
Use MSDNSamples
create table TableA(LevelValueId int identity(1,1) primary key, name varchar(100))
Insert into TableA(name) Select 'R1'
Insert into TableA(name) Select 'R2'
create Table TableB(ChildId int identity(100,1),name varchar(100), LevelValueID int references TableA(LevelValueId))
Insert into TableB(name,LevelValueID) Select 'Childname1',1
/********************************SAMPLE TARGET***************************************************************/
/********************************SAMPLE SOURCE***************************************************************/
Use Sample
create table TableA(LevelValueId int identity(1,1) primary key, name varchar(100))
Insert into TableA(name) Select 'C1'
Insert into TableA(name) Select 'C2'
create Table TableB(ChildId int identity(100,1),name varchar(100), LevelValueID int references TableA(LevelValueId))
Insert into TableB(name,LevelValueID) Select 'Kidname1',1
/********************************SAMPLE SOURCE***************************************************************/
USe MSDNSamples
/********************************MIGRATION INTERMEDIATE TABLE***************************************************************/
--Migration table
Create table Mg_TableA(LevelValueId int, NewValueId int)
/********************************MIGRATION INTERMEDIATE TABLE***************************************************************/
/********************************ACTUAL MIGRATION FOR MASTER TABLE***************************************************************/
MERGE INTO TableA
USING sample.dbo.TableA AS tv
ON 1 = 0
WHEN NOT MATCHED THEN
INSERT(name) Values(tv.name)
Output tv.levelValueId ,inserted.LevelValueid INTO
Mg_TableA;
/********************************ACTUAL MIGRATION FOR MASTER TABLE***************************************************************/
/********************************ACTUAL MIGRATION FOR CHILD TABLE***************************************************************/
Insert into TableB (name,LevelValueID)
Select A.name,B.NewValueId From sample.dbo.TableB A
Inner join Mg_TableA B on A.LevelValueID = B.LevelValueId
/********************************ACTUAL MIGRATION FOR CHILD TABLE***************************************************************/
/********************************TEST THE VALUES***************************************************************/
Select * From TableA
Select * From Mg_TableA
Select * From TableB
/********************************TEST THE VALUES***************************************************************/
Drop table TableB,Tablea,Mg_TableA
Use Sample
Drop Table TableB,Tablea

Similar Messages

  • Different ways to Transfer data from one database to another database

    Hi all,
    What are the ways to transfer data from one database to another database. With the following options, i Can transfer data as far as i know. Please
    correct me if i am wrong or tell me if there is any other options are available.
    1) Create database link/connection string and using this string and COPY command, we can transfer data.
    2) By using Export and Import utilities.
    I told first one to my interviewer, he told, its strange, by using, COPY command also can we transfer data ? As far as i know, we can transfer data. Am i right ?
    Thanks in advance,
    Pal

    transfer data from one database to another database.You mean store the data of one to another?
    1) Create database link/connection string and using this string and COPY command, we can transfer data.every SELECT on a DB-link is transfering data. And you can have all kind of transfers and store on the e.g CTAS of materialized views or.... the SQL*PLUS COPY :
    The COPY command is not being enhanced to handle datatypes or features introduced with, or after Oracle8i. The COPY command is likely to be made obsolete in a future release.
    But there are many others. Check for ORACLE Streams, and the "COPY" your interviewer was mentioning is about the operating file system COPY right? That's transportable tablespaces.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17120/tspaces013.htm#ADMIN11403
    -- andy

  • Transfer data from one database to another

    Hello,
    We have an application which uses an Oracle 9i server database. On this server we have two databases ( one for test and one for production ).
    From time to time it's required to transfer data from production database to test database.
    The steps followed by the ones which made the transfer are:
    a) drop the user schema ( the one which contains all data)
    b) recreate the user
    c) import the data ( using import utility )
    d) compile invalid object ( what this will mean I don't know)
    It's not possible to delete only the content of the tables and then import data from a dump file? In this way the steps c) and d) will no longer be required. If this is possible can you tell me if is there a command which will delete all data from all table ( almost 2000 tables)?
    Thank you fro your help!

    I think ..following a,b,c,d is the best way to maintain consistency. you are just thinking about the data in the tables, but what about the changes in views,procedures,functions etc....
    compile invalid object ( what this will mean I don't know)create a file xxx.sql with following code and execute it from sql*plus
    set echo off
    set head off
    set feedback off
    set timing off
    spool compile_invalid_obj.sql
    select 'ALTER '||DECODE(OBJECT_TYPE,'PACKAGE BODY','PACKAGE',OBJECT_TYPE)||' '||OBJECT_NAME||' '||DECODE(OBJECT_TYPE,'PACKAGE','COMPILE PACKAGE;','PACKAGE BODY','COMPILE PACKAGE;','COMPILE;')
    from user_objects
    where status = 'INVALID';
    spool off
    set feedback on
    set echo on
    set timing on
    @compile_invalid_obj.sql
    HTH
    --Chaitanya                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to transfer app data from one mac to another without using syncing of the iphone?

    Right, recently I have tried to change which computer my Iphone syncs with so that my older mac can be sold or disposed of in some profitable form. I have successfully synced all of my music off of one mac onto another via home sharing at which point I connected my phone to my new computer which suggested that the phone needed a software update. Immediately after doing this I realised that my updated Iphone 3GS would no longer sync to my old computer and attempted to sync it just to confirm this- it failed and stated that the iphone could only sync with itunes 10.1 which is a higher spec than that mac can hold. I then feeling doubtful that things would work out tried to carry on as if this problem were absent but I later discovered that I could only transfer the apps that I had synced to my phone to my new mac and all unsynced apps appeared lost because as I stated previously I could not sync with my older mac which contains all of their data. I have consulted the online apple manual for the phone and all it states is the method of transferring purchases in itunes which I tried and is what lead to the copying of my synced apps on to my new mac. What I am asking is is their anyway that I can 'cheat' so to speak at app transfers. I know that somewhere on my old mac the files are stored with the information of the lost apps but I cannot locate them and would not know how to merge them into my newer itunes if I were to copy and paste them to a memory stick (assuming that this is the right method) Other than this is their any other way of downgrading the upgrades of an iphone or somehow tricking itunes into running a higher update than the computer spec? I've tried all I can and this is really annoying- please help!!!!!!

    I'm not entirely sure what you're asking... I'll have to look on my Mac at home to see exactly where they are, but you should just be able to copy all the apps from your old machine to thumb drive or over the network and put them in iTunes on the new one, then sync. Right click on one of the apps in your iTunes library and choose Show in Finder. That will point you to where they are.
    If you're asking how you can do this and maintain data contained 'within' the apps themselves (high scores, game progress, etc), I don't think there's any way you can do that.

  • How to transfer data from one table to another without duplicates

    This is what I use to quote bathroom remodels. The first thing I do is completely fill in the Master Item List with every Product or Service we can think of to do the project. The Type column has a pop-up menu which includes Combo because some Contractors don't separate the Product from Labor. The Category Totals Table is useful but since some Contractors provide Product and Service at the same time on one invoice I don't get accurate breakdowns for generating my invoices.
    What I would like is to transfer all Vendor names included in the project to the Vendor Totals Table but without any duplicates. Some Contractors might perform services in several categories. I've read many listings in the forum and am just not seeing the answer.
    I have a sample file ready to send. I don't see a way to send it with this message. First Post! Sorry!
    Thank You
    Jeff

    jwoods007 wrote:
    What I would like is to transfer all Vendor names included in the project to the Vendor Totals Table but without any duplicates.
    Hi Jeff,
    Welcome to Apple Discussions and the Numbers '09 forum.
    If your Vendor names (including duplicates) are all in the same column of the source table, it shouldn't be difficult to transfer them to a second table using the technique described below.
    For the example, the source table is named Main and has one header row, the Vendors are listed in column C (starting at C2), and column B is used as an index column. Note that to use VLOOKUP, the index column must be to the left of the Vendor column.
    The index is generated using the following formula in B2, and filled down to the end of the column:
    =IF(COUNTIF(C$1:C2,C)=1,MAX($B$1:B1)+1,"")
    On the second table, Vendor List, the following formula is used in Column A (starting at A2) to collect the indexed vendors from the Main table"
    =IFERROR(VLOOKUP(ROW()-1,Main :: B:C,2,FALSE),"")
    IFERROR is used to trap the "couldn't find" error in the 'empty' rows of Vendor List.
    'FALSE' displays as "exact-match" in the formula, and prevents the rpeated listing of the last vendor that would be created by 'close-match'.
    Regards,
    Barry

  • Transfer of Data from one Database to Another

    Respected Guys
    Is there any way to transfer few fields from different tables located on a Database Server used by SAP to an other database used by an another application. The other database also have same fields and and Tables structure.
    Both databases are located on different servers and are oracle9i.
    Is there any way to transfer real time data from one database to another. If not then any way by which we can preiodically can transfer the data.
    Thnx

    Hi
    U can use a <a href="http://help.sap.com/saphelp_nw04s/helpdata/en/9c/d736b880c34f76b507bac7751a0474/frameset.htm">DBCON (Database Connection) tool</a>.
    Here you should call another database and write SQL native code in order to transfer/read the data.
    Max

  • How to copy the data from one database to another database without DB link

    Good Day,
    I want to copy the data from one database to another database with out DB link but the structure is same in both.
    Thanks
    Nihar

    You could use SQL*Plus' COPY command
    http://technology.amis.nl/blog/432/little-gold-nugget-sqlplus-copy-command
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/apb.htm#sthref3702
    Edited by: Alex Nuijten on Sep 16, 2009 8:13 AM

  • How to transfer DATA from one machine to another using  DBlink

    I want to transfer data from one machine to another both having oracle 8.0.5 with AIX operating system using DB link. CAn any one help me in this task

    Step one - Create and test SQLNet connections between the databases.
    Step two - Create at least on database like from one database to the other:
    CREATE DATABASE LINK linkname
    CONNECT TO user identified by password
    USING 'tnsnamesentry';
    Step three - use the dblink linkname in dml statements eg:
    insert into emp@linkname
    (select * from emp);

  • Can I transfer pictures from one iPad to another without going over iTunes?, can I transfer pictures from one iPad to another without going over iTunes?

    can I transfer pictures from one iPad to another without going over iTunes?, can I transfer pictures from one iPad to another without going over iTunes?

    Yes, use 3rd party apps like Photo Transfer App.
    http://i1224.photobucket.com/albums/ee374/Diavonex/Album%205/69507ce7f854c405f54 77bea99f4d498.jpg
    http://i1224.photobucket.com/albums/ee374/Diavonex/Album%205/79b3173fda7b6a6e148 5b463198f6acf.jpg

  • How can you transfer data from one ipod to another ?

    How can you transfer data from one ipod to another ipod ?

    The geniusbar told me what to do, I understood but there is still a problem for me >:/ It's not showing up though. Like "device."  Nothing is happening, and I tried as soon as I got home. Then after half an hour, then an hour, then 3 hours. My problem is that it's not showing up! It's stuck in recovery mode! There's still like 25% battery. So I have no idea why.

  • How do I transfer data from one iPhone to another?

    How do I transfer data from one iPhone to another?

    If your old device is an Apple using iOS 5 or later, and you have an iCloud account, you can transfer all your saved messages, email accounts, photos, notes, and other personal settings to your new iPhone.
    Here's how...
    Connect your old Apple device to WiFi and to a power source.
    Back it up to iCloud by going to Settings > iCloud > Storage & Backup and toggling iCloud Backup on. The time it takes to ba ckup depends on how much data you have and on the speed of your internet connection.
    iCloud backs up your device once a day. If it needs backing up before you transfer to your new iPhone 5, tap Back Up Now in Settings > iCloud > Storage & Backup. Do not start transferring before the backup is finished.
    Turn on your new iPhone and complete the setup by selecting your language and country, and choose whether to enable Location Services. When prompted, choose your WiFi network.
    When prompted to set up, choose Restore from iCloud Backup, tap Next, and enter your Apple ID and password.
    Select the backup of your old device and tap Restore. Wait until the device has finished restoring from the backup.
    When the restore process is complete, your iPhone will restart and be ready to use.
    Connect your iPhone 5 to iTunes to sync data not contained in the backup (such as music, videos, apps, and so on). You can choose the data that are synced by clicking the syncing tabs in iTunes.

  • How do I transfer files from one computer to another without using cables??

    How do I transfer files from one computer to another without using cables?

    Wifi network
    Email
    Thumb Drive
    Online storage such as, iCloud Google Docs, SkyDrive, etc.

  • How to move only subset of data from one database to another?

    Both source & destination are Oracle11g databases.
    The requirement details are as below,
    1) The database contains static as well as transactional data for telecom domain.
    2) We have to move region-wise data from one database to another.
    3) There are around 10 regions.
    4) The region wise data extraction from source db is based on around 40 to 50 tables. Rest of the tables contains
    static data & it will not change.
    5) The volume is around 1 million subscribers per region.
    6) The migration is required because
    a) The client is upgrading its base product which uses this database
    b) There is a change in structure of static tables
    c) Hardware upgrade
    d) The client want to start with single region on new database & rest of the regions will be operated from old
    database.
    7) Keep execution time to very minimum.
    I am thinking to have solution as below,
    1) Create destination database with upgraded db structure (as mentioned in 6b)
    2) Create database links to access source db in destination db.
    3) Write SQL queries to fetch data from all the respective tables for a specific region
    4) Write separate PL/SQL blocks for each table to fetch data from source db & insert into respective table in
    destination db
    a) Use FOR ALL & bulk collect to improve the performance
    b) Divide table data into multiple chunks & execute parallel batches (around 10) to insert the data
    5) Validate pre & post counts to verify the success of migration
    Is there any other better way?
    Regards,
    Sandeep

    How to move only subset of data from a partiular table by using transportable tablespace?
    E.g. SUB table using SMP_SUB tablespace contains subscriber data in source database.
    The indexes defined on SUB table are under SMP_IDX_SUB tablespace
    The subscribers data can be categorized by different regions, say region_id column. Then how to move data & indexes of SUB table from source db to destination db?
    any specific example would be helpful.

  • How to transfer data from one macbookpro to another

    how to you transfer data from one macbookpro to another. the other one was stolen.

    If your computer was stolen and you don't have a data backup, you can't transfer data from the stolen computer to your new one. If you have a data backup, restore the data to the new computer.

  • How to transfer music from one iphone to another without paying

    how do you transfer music from one iphone to another without paying?

    It depends on who owns the phones.  If you are just upgrading from one iPhone to another, you can use iTunes.
    If you're talking about "giving" the music to someone else with a different Apple ID, that's a whole different question.

Maybe you are looking for