Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Copying records from on DB to another DB
Message
 
 
To
11/10/2016 13:04:17
John Baird
Coatesville, Pennsylvania, United States
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01641828
Message ID:
01641833
Views:
38
>>I have a challenge of copying some records from two tables of one database to the two tables (of the same name) in another database. Here is why it is a challenge.
>>
>>The table names are:
>>PM_CATEG - Categories which has a PK field PMCATEG_PK
>>PM_TASK - PM Tasks which has a PK TASK_NO (Identity) and PMCATEG_PK (set matching the PMCATEG_PK in PM_CATEG table).
>>
>>Example:
>>
>>PM_CATEG
>>CATEGORY     PMCATEG_PK
>>PUMP              10
>>
>>PM_TASK
>>PMCATEG_PK               TASK DESCR    TASK_NO
>>10                      List of items       200
>>10                      Another list        201
>>10                      Another list        280
>>
>>
>>(Note that the TASK_NO is not always sequential because it could have been created at different time).
>>
>>Now I need to copy the records from PM_CATEG and PM_TASK of one DB to another for CATEGORY = 'PUMP'
>>
>>I would use the INSERT command but I have to dynamically INSERT into the PM_CATEG and then using a newly created PMCATEG_PK copy the PM_TASK.
>>
>>Is this possible or I am better off creating a VFP PRG to do it?
>>
>>TIA
>
>There's a command called Set Identity_Insert that does the trick.... http://www.sqlteam.com/article/how-to-insert-values-into-an-identity-column-in-sql-server

Thank you. I can see how this approach can be useful in other cases (hence I will save this link for future). But in this case it won't work. The Identity values in the From database are smaller than the one in the To database. Therefore, even with the set identigy_insert off SQL will not allow it. I am going to start working on a VFP-way (a procedure) of doing it.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform