Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fBC7dYm01513 for ; Wed, 12 Dec 2001 02:39:34 -0500 (EST) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.4/8.11.4) id fBC7NbD79657 for pgsql-sql@postgresql.org; Wed, 12 Dec 2001 02:23:37 -0500 (EST) (envelope-from news) From: Arian Prins X-Newsgroups: comp.databases.postgresql.sql Subject: Re: How would i do this? Date: Wed, 12 Dec 2001 08:23:30 +0100 Organization: Academic Medical Center, The Netherlands Lines: 63 Message-ID: <3C1705F2.4E8FD320@zonnet.nl> References: <9v5m86$26uo$1@news.tht.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.surfnet.nl X-Mailer: Mozilla 4.7 [nl] (WinNT; I) X-Accept-Language: nl Cache-Post-Path: sphere.amc.uva.nl!unknown@amcnip36143.amc.uva.nl X-Cache: nntpcache 2.4.0b2 (see http://www.nntpcache.org/) To: pgsql-sql@postgresql.org X-Archive-Number: 200112/122 X-Sequence-Number: 5945 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