我已經搜索了一個解決方案,並找到了幾個示例,但沒有一個適合我的場景。將相同的GUID插入到兩個表中
我有一個[source]表和兩個目標表[table1]和[table2]。 [table1]和[table2]都有一個Id列(UniqueIdentifier)。 [table1]中的所有列都有默認值,包括UniqueIdentifier。
[table1]是[table2]的父級,包含日期 - 時間數據,用於跟蹤何時插入,修改,刪除記錄。 [table2]是一個詳細表格,描述[table1]中的記錄。
我需要從[source]中選擇所有內容,並將其插入到[table1]和[table2]中,保留[table1]插入期間生成的Id,因此我可以將同一個Id與選定的數據一起插入[table2]來自[來源]。
[source]
col1, col2, col3, col4 <------This data needs to be inserted into [table2]
[table1]
Id*, date-created, date-modified, to-date <-------these all have default values
[table2]
Id*, name, description, category <-------Id generated in [table1] needs to match here
希望我明確了這一點。讓我知道你是否需要更多細節。謝謝!
相關:http://stackoverflow.com/q/42648/1583 – Oded 2013-05-10 16:12:16
看起來你需要在第二個表中創建一個外鍵,鏈接到第一個(主)表中的GUID – 2013-05-10 16:12:30
外鍵存在已經,但我仍然不確定SELECT | INSERT將被執行。你會碰巧有這樣的例子嗎? – Jonathan 2013-05-10 16:37:44