我暂时没有使用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
我先插入word,然后插入文件,然后插入fileWord?
答案 0 :(得分: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)