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 > Data Modeling Problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-11-09, 09:20
sxturner sxturner is offline
Registered User
 
Join Date: Mar 2009
Posts: 2
Data Modeling Problem

I'm trying to model something fairly simple, but to my shame I'm having a hard time figuring out a good design!

The situation is I have a set of web pages that can occasionally display announcements. An announcement can appear one one or many pages; also some announcements should appear on all pages (i.e. "global announcements").

Here's my first attempt at a model, a simple many-to-many relationship.

Data Modeling Problem-announcements_data_model_manytomany.png

What's causing me problems is the notion of an announcement appearing on all pages - I'm not sure whether to use a "page" called "global", and have global announcements associated with that page. If I do this, I need to make sure that these announcements can't also be associated with individual "real" pages. There's nothing I can see in the design that would enforce this rule, so it doesn't feel right.

Thanks for any help -
Steve
Reply With Quote
  #2 (permalink)  
Old 03-11-09, 09:56
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
there might be other ways to handle this, but to me the simplest is to have a column in the announcements table called isGlobal or similar

in the admin process to add an announcement, whether a global one or otherwise, the first thing we do is INSERT the announcement -- until then, we don't have a PK yet that we can reference in the page_announcement FK

so if we've just added a new global announcement, we wouldn't let the admin user even try to link it to any specific pages
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-11-09, 13:40
sxturner sxturner is offline
Registered User
 
Join Date: Mar 2009
Posts: 2
Thanks for the reply - I like that idea, it's nice and simple. One issue that remains though, is that there's nothing in the data model to enforce the rule that global announcements shouldn't be associated with any pages.

I probably will not fret about that too much though, and enforce the rule through application code.

Thanks again,
Steve
Reply With Quote
  #4 (permalink)  
Old 03-11-09, 15:57
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
there is a way, but it involves a compound PK and a CHECK constraint

application logic suffices nicely here

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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