开发者

Why shouldn't I use a field with a "set" datatype? Alternative layouts?

I've been designing my database layout and I guess I need a way to place multiple entries in a single field. I want to create a row for each student in the database, and I want one of the fields to contain their classes. I don't want开发者_Python百科 to do a bunch of separate fields because there is not a set amount of classes a student can have, it can vary. I was reading up on the SET datatype and read the paragraph about why not to use SET. I was wondering if anyone could make a more "english" explanation of this, or if it actually ok to use then tell me so. If it's not, could anyone suggest a better layout for the current situation? Much appreciated, as always!


You may wish to store classes as a separate entity. For that, you need another table to store the classes, and a third table linking the two tables:

students: id, name, age, ...

classes: id, name, time, professor, ...

student_class: student_id, class_id

Then you'd use JOIN queries to retrieve the data.


With a SET, you have to predefine all possible values. You probably want a TEXT type datatype and separate values with some delimiter (like a semi-colon or other).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜