| Author |
Topic |
|
GoDaddy
Yak Posting Veteran
64 Posts |
Posted - 2009-02-12 : 11:54:59
|
| I have a table A that I need to migrate data into another table B, kinda like a merge. Table A will be Deleted. Now I have Table C that has a FK on tableA. So I have to create another column on table C that has a FK on Table B and reference it to the new migrated record. How can I achieve this, I'm really a noob in sql sorry.Thanks for the help |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-02-12 : 12:10:02
|
| Migrate all data from Table A to Table B with Export/Import Wizard.Apply all keys and constraints from TableA to TableB changing Reference to Table B(Not Table A). Drop Table A and add necessary constraints from Table C to Table B. |
 |
|
|
GoDaddy
Yak Posting Veteran
64 Posts |
Posted - 2009-02-12 : 13:05:04
|
| In need to do this in a script file without using any tool but only sql. |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-02-12 : 13:06:00
|
| That is SQL and its feature. |
 |
|
|
GoDaddy
Yak Posting Veteran
64 Posts |
Posted - 2009-02-12 : 13:13:33
|
| but you are talking about export/import wizard ....... or is a sql statement ? |
 |
|
|
GoDaddy
Yak Posting Veteran
64 Posts |
Posted - 2009-02-12 : 13:14:49
|
| yeah looks like its a wizard. I can't use that. I need something with sql. to go through all the rows of Table A and then insert them into table B for example. |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-02-12 : 13:16:33
|
Then use:Select * into [TABLE B]from [TABLE A] |
 |
|
|
GoDaddy
Yak Posting Veteran
64 Posts |
Posted - 2009-02-12 : 13:17:00
|
| the thing is that Table B doesn't have the same structure as Table A |
 |
|
|
GoDaddy
Yak Posting Veteran
64 Posts |
Posted - 2009-02-12 : 13:23:28
|
| something with cursors maybe |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-02-12 : 13:25:38
|
quote: Originally posted by GoDaddy the thing is that Table B doesn't have the same structure as Table A
Can you layout the structures of tables? Also can you elaborate what you exactly need? |
 |
|
|
GoDaddy
Yak Posting Veteran
64 Posts |
Posted - 2009-02-12 : 13:35:15
|
| lets say Table A ( id, name )Table B ( id, name, notes, code )Table C ( id, aId )So I want to migrate the data from A to B. So only the id and name in B will be filled from A. And id in B will also be different from A (a new Id). Now I need to add a new column in C bId, that will reference to the new mirgrated record in B. |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-02-12 : 13:48:07
|
| Is ID column related between A and B? Also what do you mean by New ID for B(Different than A)? |
 |
|
|
GoDaddy
Yak Posting Veteran
64 Posts |
Posted - 2009-02-12 : 13:58:53
|
| We have a table called Identities, where it provides the next Id that can be used for each table. So lets say table B has like 5 records already. in that Identities table you'd have something like TableName, nextIdB, 6So the next record that is going to be insert into B must have 6 as an ID. So when insert a record from A to B, the new record of B will have ID = 6 and not the ID of record A. |
 |
|
|
|