Re: How would i do this?
От | Arian Prins |
---|---|
Тема | Re: How would i do this? |
Дата | |
Msg-id | 3C1705F2.4E8FD320@zonnet.nl обсуждение исходный текст |
Список | pgsql-sql |
Hello John, You would really have to read-up on relational theory. There is a lot to be found on the web. And if a take a peek at our books I see: Date, C.J., An Introduction to DATABASE SYSTEMS. But for a quick explenation: think in relations. Think in on of these posible relations: x has ZERO or ONE y (example in a hospital setting: a patient x has zero or one cause of death y) x has ZERO to MORE y (example: a student x has followed zero to more classes y) x has ONE to MORE y x has ZERO to MORE y, AND, y has ZERO to MORE x (example teachers x that teach to students y.... a teacher can have multiple students and a student can have multiple teachers). One piece of your example can be modeled like this: A Class is comprised of students: - you'd have a table that identifies classes: class (class_id, class_name, ..other items that you'd like to record....) - and a table that identifies students: student (student_id, student_name, student_adres.............) - and a table that lists which student attends which classes: students_attending_classes (students_attending_classes_id, class_id, student_id,......... ) Because the last table has multiple rows with one student in it, a student can attend multiple classes, and a class can be attended by multiple students. If a student can attend _only_ one class then you'd put the class_id in the student-table. But... there is A LOT to know... You can normalise into the 3rd, 4th or 5th form, etc. etc. etc so I'd suggest you'd find some sites / literature. Succes, Arian. John Hughes schreef: > I am new to DB programming, so im not too sure about how to implement my DB. > > Here is what i need: a DB with tables of: > > 1. Students. > 2. Classes > 3. Teachers > 4. Assignments > > Each teacher can be assigned a class, which is compromised of a list of > students. Each class can be given assignments. > > Coming from a programming background, I could do this in c++ very easily. I > actually started inmplementing it in a similar fasion: each student class > teacher ect would have a uniqe id in the database, and, for example, a > class would include an array of integer student id's. > > This seems really error prone, and not very efficient. > > what is a better implementation? > > John Hughes
В списке pgsql-sql по дате отправления: