开发者

When adding data to a table, it doesn't show up in the Foreign key of the other table

I have a table COURSE which 开发者_运维百科has two attributes COURSECODE (PK) and COURSENAME

I also have another table COURSEUNIT, which has three attributes COURSECODE (PK) (FK) UNITCODE (PK) (FK) and CREDIT .

When I add data to the table COURSE it doesn't add the data to the COURSEUNIT table. What is the problem?


Foreign key does not mean that you get one row for each key in the referenced table. It only means that any row in the COURSEUNIT table must reference an existing row in COURSE.


Those are 2 different tables and you have to manage the relation, you have to insert the data first in the course table then take the id that will be generated from this insert and make another insert in the coursecode table, they will not be inserted automatically.


No problem there, that's how SQL works, you'll need a second INSERT statement to populate the COURSEUNIT table.


You need to write the query to populate the second table, how else will it know what values besides the FK to put in it? Child tables do not auto populate in any database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜