Taztingo
Taztingo

Reputation: 1945

Updating Foreign Key Tables

I haven't worked with SQL in a while, and I can't seem to remember how updating foreign key tables work. Do you have to insert the element into both tables? How would I get the correct primary keys if I did it that way? I can't seem to remember, and I tried looking up some basic tutorials. The tutorials were mainly just what foreign keys were not actually inserting data into the tables.

For example if I have:

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

Do I first insert into word, then into file, and then into fileWord?

Upvotes: 0

Views: 104

Answers (1)

waka-waka-waka
waka-waka-waka

Reputation: 1045

word, fileword and then file.

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)

Upvotes: 1

Related Questions