tags:

views:

31

answers:

2

I have a database setup with many tables. To Find a User's Computer it would take joins across 6 different database tables.

My User table and Computer table are not directly connected.

Should I just connect the user and computer table with a foreignKey? Or do all of the Joins?

Or am I missing something else?

A: 

Unless performance is an issue, don't denormalise your data. It's a maintenance hazard. If you're struggling with all the joins, why not make a view to simplify matters?

spender
this may be a good idea. I am not familiar with views so I just googled them and they might work. Is there a simple rule/example of when to use a view and when not to?
SteveK
No, not really, but there are very sensible suggestions concerning keeping your data normalised. I would always opt for a normalised approach over duplicating data in more than one place. When you return to maintain the DB in 6 months time, will you remember your denormalised setup? When you need to perform updates to certain parts, will you remember to update the duplicated data? Atomically? You might gain in the short term by duplication, but there are almost always unwanted consequences. A correctly keyed/indexed lookup over several tables isn't a bad thing.
spender
A: 

Whether you do joins or denormalise is a function of your database usage. The answer is that it depends. How often is the join done for example? What is the goal - maintennance effort? Performance? Development Effort?

Preet Sangha
The goal is the tell which computer a user is using. Is it possible that I setup my database schema incorrectly?
SteveK