If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > Help creating a simple WebLogin Relation

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-03-09, 20:44
roland23 roland23 is offline
Registered User
 
Join Date: Apr 2009
Posts: 4
Smile Help creating a simple WebLogin Relation

Hey,

I have a preexisting database with tables Teacher, Principal, AssistantPrincipal. I want to create a WebLogin Entity (WebLoginId, Username, Password) that shares a one to one relationship with each of the tables above. For every teacher, there is exactly one corresponding WebLogin. For every WebLogin, there is exactly one corresponding teacher.

My first thought is to create a relation such as WebLogin(WebLoginId, Username, Password, TeacherId, PrincipalId, AssistantPrincipalId).
The TeacherId, PrincipalId, and AssistantPrincipalId would be foreign keys into their respective tables. However, in this method, two of the employee IDs are always left null.

Is there a more elegant solution? I'm quite new at this.

Thanks!
Reply With Quote
  #2 (permalink)  
Old 04-08-09, 08:38
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Given your existing data model, there probably isn't. Your solution is quite a standard one anyway - with a CHECK constraint to ensure that one and only one of TeacherId, PrincipalId, and AssistantPrincipalId is populated on each row.

You could turn it around and hold a WebLoginId in the other 3 tables, but then it would be hard (not impossible) to ensure that a Teacher and a Principal (say) don't share the same login details.

Maybe Teachers, Principals and Assistant Principals should all have been in one table in the first place, but it's too late to worry about that now.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 04-08-09, 10:25
roland23 roland23 is offline
Registered User
 
Join Date: Apr 2009
Posts: 4
Thank you for the response Tony.

Is it a better practice to split the table into several smaller linking tables to eliminate the nulls?

WebLogin(WebLoginId, Username, Password)
WebLoginTeacher(WebLoginId, TeacherId)
WebLoginPrincipal(WebLoginId, PrincipalId)
Reply With Quote
  #4 (permalink)  
Old 04-08-09, 10:44
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
I don't think so, no. It has the same issues as putting foreign keys to WebLogin in the other 3 tables, i.e. hard to ensure a Teacher and a Principal don't share the same WebLogin. Plus it involves extra tables.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #5 (permalink)  
Old 04-08-09, 15:19
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
Looks like a supertype / subtype example to me:

WebLogin (TeacherId, WebLoginId, Username, Password)
KEY (TeacherId)
KEY (WebLoginId)

Teacher (TeacherId) KEY (TeacherId)
Principal (TeacherId) KEY (TeacherId)
AssistantPrincipal (TeacherId) KEY (TeacherId)


Teacher is the parent table being referenced by all the others.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On