我有兩個表與數據:GroupTable和PeopleTable。SQL Server:將表的行復制到同一個表
grouptable將有此列:ID,大陸,國家
PeopleTable有此列:ID,的groupId,名
的groupId是一個外鍵GroupTable.id
兩個表已填充從我的應用程序。我想要做的是創建一個存儲過程,將兩個表的內容複製到相同的表中,但更改GroupTable的continent
列。因此,PeopleTable中的新行將指向GroupTable中的新行。輸入存儲過程是@sourceCont,@destinationCont
我有什麼:
GroupTable:
id | continent | company
0 | europe | aa
1 | europe | bb
2 | europe | cc
PeopleTable:
id | groupId | name
0 | 0 | John
1 | 0 | Mary
2 | 0 | Nick
3 | 1 | Peter
4 | 2 | Michel
這就是我想要的(@sourceCont =歐洲,@destinationCont =美國)
GroupTable:
id | continent | company
0 | europe | aa
1 | europe | bb
2 | europe | cc
3 | america | aa
4 | america | bb
5 | america | cc
PeopleTable:
id | groupId | name
0 | 0 | John
1 | 0 | Mary
2 | 0 | Nick
3 | 1 | Peter
4 | 2 | Michel
5 | 3 | John
6 | 3 | Mary
7 | 3 | Nick
8 | 4 | Peter
9 | 5 | Michel
mysql或sql-server ....? – scaisEdge