2010-09-16 108 views
-2

我想將表的主鍵的值插入SQL Server中另一個表中的外鍵。在SQL Server中將值從一個表插入到另一個表中

請幫我..

+1

你嘗試過什麼?你在哪裏遇到麻煩?你是否得到一個錯誤 - 如果是這樣的話:它是什麼? – 2010-09-16 11:04:41

+0

你基本上問過兩次相同的問題:http://stackoverflow.com/questions/3726498/how-to-insert-values-from-one-table-to-another-using-radio-button-control/3726767 #3726767 – IrishChieftain 2010-09-16 13:29:27

回答

6
Insert Into FKTable (FKValue) 
Select PKValue 
From PKTable 
0

下面是一個例子:

INSERT california_authors (au_id, au_lname, au_fname) 
SELECT au_id, au_lname, au_fname 
FROM authors 
WHERE State = 'CA' 
-1

SELECT的PrimaryKey INTO newtable的 FROM OldTable

+0

僅當NewTable不存在時纔有效... – JNK 2010-09-16 13:01:19

相關問題