Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^5: Avoiding SQL double jeopardy

by Pope-O-Matik (Pilgrim)
on Jun 28, 2015 at 09:25 UTC ( [id://1132358]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Avoiding SQL double jeopardy
in thread Avoiding SQL double jeopardy

Thank you, i think i got it now. :) Two more clarifications, though: Can there be more than one teacher per session? Can there be more than one student per session? That is, "by definition" as opposed to how it just happens to work out.

Replies are listed 'Best First'.
Re^6: Avoiding SQL double jeopardy
by GrandFather (Saint) on Jun 28, 2015 at 10:21 UTC

    Hmmm there is a little confusion of nomenclature (my fault). Properly speaking we have one XR (eXperience Replication) session a week. People pair up as a teacher and learner. If there is an odd number of people one "pair" will have one teacher and two learners.

    The current Sessions table identifies sessions by DrawDate and contains a "SessionId" which I should rename to PairId. There will be multiple pairs per weekly session.

    PairId is unique in the Sessions table but there will be multiple entries (generally two) in the SessPeople table (which I should rename to the Pairs table) for each PairId.

    Perl is the programming world's equivalent of English

      Okay, so always on teacher, 1 or more Learners.

      Are subjects a set thing? That is, only a limited amount of subjects (expanded at will), or can it be anything, that is, just a quick note.

      I don't believe you need a session id. As one person can only teach one session at a time, the natural key is Teacher/Time. And for Person, shouldn't it be employee? And, do Employees already have unique id, such as their company email address?

        Yes, teacher ID could be used as the session (pair) ID.

        Available topics are expected to be quite dynamic. Someone could change the topic they offer each week, or stick to the same topic for long periods of time, or have several topics on offer at the same time.

        Person / Employee is not an interesting distinction. This system is unrelated to any "business" database. In fact it's quite likely that visitors will take part in sessions.

        Email addresses are stored in the People database as an ID, but can be changed. The autoincremented internal ID is the "authoritative" identifier in the system.

        Perl is the programming world's equivalent of English

      Here's an attempt at it:

      CREATE TABLE Employee ( Id NUMBER PRIMARY KEY AUTOINCREMENT, First_Name TEXT, Last_Name TEXT ); CREATE TABLE Topic ( Name TEXT CHECK(Name = LOWER(Name)) PRIMARY KEY, Description TEXT ); CREATE TABLE Session ( Teacher INTEGER REFERENCES Employee, Start DATETIME, Finish DATETIME, Topic TEXT NOT NULL REFERENCES Topic, PRIMARY KEY(Teacher, Start) ); CREATE TABLE Session_Learner ( Teacher NUMBER, Start DATETIME, Learner NUMBER NOT NULL REFERENCES Employee, -- FOREIGN KEY(Teacher, Start) REFERENCES Session, PRIMARY KEY(Teacher, Start, Learner) ); CREATE VIEW Session_Employee AS WITH Session_Teacher_Learner AS ( SELECT Session.Teacher, Session.Start, Session.Topic, Session_Learner.Learner FROM Session, Session_Learner WHERE Session_Learner.Teacher = Session.Teacher AND Session_Learner.Start = Session.Start ) SELECT Teacher, Start, Topic, Teacher Employee FROM Session_Teacher_Learner UNION ALL SELECT Teacher, Start, Topic, Learner FROM Session_Teacher_Learner;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1132358]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-03-29 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found