2013-10-22 118 views
0

我在一段時間裏還沒有用過SQL,而且似乎還記得如何更新外鍵表工作。你是否必須將元素插入到兩個表中?如果我這樣做,我將如何獲得正確的主鍵?我似乎無法記住,並試圖查找一些基本的教程。這些教程主要是外鍵實際上沒有將數據插入表中。更新外鍵表

例如,如果我有:

Table File 
fileId - Primary Key 
fileName - Normal column. 
fileUrl - Normal column. 

Table fileWord 
fileId, wordId - Primary Key, Foreign Key 
count - Normal column. 

Table word 
wordId - Primary Key 
word - Normal Column 

難道我第一次插入字,遂成文件,然後進入fileWord?

回答

1

word,fileword然後文件。

table word has no foreign keys - safe to insert.(first/second) 
table file has no foreign keys, safe to insert. (first/second) 
table fileword has one foreign key referring to word - safe to insert after table word. (third) 
+0

對不起,我搞砸了。我修好了我的外鍵。你認爲你可以再看一次嗎?我只是插入到文件中,並且第一個字是正確的? – Taztingo

+0

是的,這是正確的。文件,單詞或單詞,文件後跟文件字。 –

+0

我的唯一的其他問題是如何插入文件字如果這些id在文字和文件是自動遞增? – Taztingo