データが2つあるテーブル: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