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 > Poor Database Design or Poor Practice?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-16-09, 19:41
Eric the Red Eric the Red is offline
Registered User
 
Join Date: May 2008
Posts: 68
Poor Database Design or Poor Practice?

I'm creating a database that looks similar to this

Code:
“Actor” Table,
|| Actor Name     ||   ActorID	|| 
|| Russell Crowe  || 	1 	||
|| Jessica Alba    || 	2 	||
.
.
.

Movie table
|| MovieID || Title || RunningTime || CompleteCast ||
|| 1	      || “Gladiator” || 234 || 1:2:34 ||
.
.
.
However, someone has told me that I have poor database design because inside my movie table "CompleteCast" I'm using delimited fields for my actors.

I've already got separate tables for both "actor" and "movies" so why is this a bad thing and what can I do to change this problem?
Reply With Quote
  #2 (permalink)  
Old 04-16-09, 23:21
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
it's a bad thing because it violates first normal form

why is 1NF important? because without it, your queries will be horrendously complex (e.g. to find all the movies a given actor is in) and slow as cold glue (because they will require table scans)

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 04-17-09, 09:26
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
Quote:
Originally Posted by Eric the Red
However, someone has told me that I have poor database design because inside my movie table "CompleteCast" I'm using delimited fields for my actors.

I've already got separate tables for both "actor" and "movies" so why is this a bad thing and what can I do to change this problem?
There's nothing fundamentally wrong with storing delimited strings in a column but in this case it's unlikely to be very practical.

For example: How will you ensure that the actor names in the cast column correspond to those in your Actor table? It's very difficult to enforce such a rule in the database. How will you locate and update every reference to an actor's name if it appears in lots of delimited strings (for example if an actor's name changes or needs correcting)? Finally, and most obviously, how do you expect to answer such queries as "Show me all the films in which Marlon Brando appeared"? It's very hard to do that efficiently if you first have to parse a string on every single row.

The solution is to create a new table that joins actors to movies, probably with just two attributes (like: ActorMovie {Actor, Movie} where {Actor, Movie} is also the key of the table). This is often called a "joining table" or "association table" although personally I don't find that terminology very useful.
Reply With Quote
  #4 (permalink)  
Old 04-17-09, 09:48
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Quote:
Originally Posted by dportas
There's nothing fundamentally wrong with storing delimited strings in a column
Do you consider delimited strings atomic then David?
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #5 (permalink)  
Old 04-17-09, 09:55
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by dportas
This is often called a "joining table" or "association table" although personally I don't find that terminology very useful.
okay, i'll bite -- what do you call it?

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 04-17-09, 10:42
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
Quote:
Originally Posted by pootle flump
Do you consider delimited strings atomic then David?
A string is a string. It's only a single value by definition. The question of whether the same information could be better stored in other ways depends a lot on the circumstances and how the data is used. Although it can be an important design issue I don't believe it's desirable to make a single universal rule about it.

1NF isn't strictly relevant here because most popular DBMSs (SQL ones) don't allow you to store more than one value in a single column anyway.

Quote:
Originally Posted by r937
okay, i'll bite -- what do you call it?
The thing is, I'm unsure exactly when a table qualifies as a "association table" anyway. It seems to me that an association table can be any table with more than one foreign key. If that's so then I don't really see why I need a special name for those tables. Having more than one foreign key isn't so special is it?
Reply With Quote
  #7 (permalink)  
Old 04-17-09, 10:47
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Quote:
Originally Posted by dportas
A string is a string. It's only a single value by definition.
but not what it represents. XML is a string. A bitmask is an integer. But what they represent is more than a single "thing".

Quote:
Originally Posted by dportas
The thing is, I'm unsure exactly when a table qualifies as a "association table" anyway. It seems to me that an association table can be any table with more than one foreign key. If that's so then I don't really see why I need a special name for those tables. Having more than one foreign key isn't so special is it?
I'd add that my internal-used-only-by-myself definition is that an association table has no non-key attributes. As such, it represents an association only and not a distinct and tangible entity.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #8 (permalink)  
Old 04-17-09, 23:12
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
In my mind, an association table can also contain a date_begin and a date_end, since many associations are time delimeted.

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #9 (permalink)  
Old 04-17-09, 23:32
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
I'd agree there. Associations can easily gather attributes, and become entities in themselves. This kind of falls in line with my "There's no such thing as a lookup table" mantra.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
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