Monday, March 19, 2012

Need some advice. Thank You.

Hello,
Today I am creating my first one-to-many relationship database.
My main table is:
USERS
Then I have 4 tables related with this one:
PAYMENTS, ORDERS, BOOKS, ARTICLES
For each user I need to create a field named VALUE.
VALUE = N(PAYMENTS)*4 + N(ORDERS)*2 + N(BOOKS)*10 + N(ARTICLES)*5
N = Number of... / Example: N(PAYMENTS) means "Number of Payments".
My questions are:
1. Should I place the value field in USERS table or create a table named
VALUES and have it connected to USERS table?
2. How can I keep my VALUE field updated for each USER?
Thank You Very Much,
Miguel> 1. Should I place the value field in USERS table or create a table
named
> VALUES and have it connected to USERS table?
None of the above. Don't store calculated values in the database. Put
the calcs in your views, queries and procs.

> 2. How can I keep my VALUE field updated for each USER?
Not a problem if you don't store the value.
If you need more help then the following article explains the best way
to post your problem here:
http://www.aspfaq.com/etiquette.asp?id=5006
David Portas
SQL Server MVP
--|||>> 1. Should I place the value field in USERS table or create a table named
Consider using a view instead. Deriving calculated values are generally
better than having them as persisted data in any base table.
This is not an issue, if a view is used. For details, see the topic on
views, creating a view and if required for any performance reasons, indexed
views, in SQL Server Books Online.
Anith

No comments:

Post a Comment