开发者

Relating two tables in a database

开发者 https://www.devze.com 2022-12-12 03:47 出处:网络
I have a \"Student\" table which should have name column. But I made another table \"StudentsName\" for name since names have three parts: firstname, mi开发者_如何学JAVAddlename and last name.

I have a "Student" table which should have name column. But I made another table "StudentsName" for name since names have three parts: firstname, mi开发者_如何学JAVAddlename and last name. Now my question is how should I relate these two tables?


If "student" table uses ids from "name" table then you want to have a FK from "students" to "name"


Yes, you need a primary key/foreign key constraint between the tables. The only question is "which table is the controlling one?" It could be the student table, in which case the name refers to the student ID in the student table. Or, it could be the name table, where the student table records the current name for a student (and there might be other tables to record the history of this student's name changes - marriage, or just legal changes of name).

0

精彩评论

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

关注公众号