January 12, 2010 at 11:33 am
Im trying to design my database tables around the scenarios listed below. I cant seem to wrap my mind around it. Any help would really be appreciated.
You have States, Credit Types, and Courses
States: NY, FL, GA
NY Allows: CreditType: 2, 4, 6
FL Allows: CreditType: 1, 3, 5
GA Allows: CreditType: 1
Course A Applies To CreditType: 1 in FL (But not GA)
Types: 1
States: FL
Course B Applies To CreditType: 1 (for GA), and 2 (For NY)
Types: 1, 2
States: GA, NY
Course C Applies To CreditType: 2 (FL), 3 (NY), 1 (GA and FL)
Types: 2, 3, 1
States: FL, NY, GA
How would you properly store this in the Database in order to search on Courses with the following:
Seerch Courses that match have a certain Credit Type or have multiple certain credit types
(Course where Type = 1)
(Course where Type = 1 or 2)
(Course where Type = 1 and 2)
Search Courses that match for a specfic or multiple states
(Course where Type = FL)
(Course where Type = FL and NY)
(Course where Type = FL or NY)
Search Courses that match a specific Type and a specific State
(Course where Type = 1 and State = FL)
(Course where Type = (1 or 2) and State = (FL and GA))
(Course where Type = (1 and 2) and State = (FL or GA))
Thanks for any help provided.
January 13, 2010 at 4:03 am
Store the Courses, Credit Types and States in separate tables.
Create a CreditTypeByState table (StateID, CreditTypeID) to store a credit type - state correspondence. Use CHECK constraints to allow only the appropriate credit types for each state.
The CourseByByState table (RecordID, CourseID, StateID, CreditTypeID) will store the courses for each state and credit type.
For example, a search looks like:
SELECT c.[Name], ct.[Name] s.State
FROM CourseByState cs
JOIN Course c ON c.CourseID = cs.CourseID
JOIN CreditType ct ON cs.CreditTypeID = ct.CreditTypeID
JOIN State s ON cs.StateID = cs.StateID
WHERE cs.CreditTypeID = <value> AND cs.StateID = <value>
This may change a little, as I am not sure I understand this: "Course A Applies To CreditType: 1 in FL (But not GA)".
January 19, 2010 at 8:06 am
This is home work, isn't it? - nothing wrong about that.
If you really want to get a grasp of it do this...
Entity-Relationships
- Identify your entities - draw it!
- Identify the relationships in between your entities
3NF
- Be sure your data model conforms with third normal form.
_____________________________________
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at Amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply