
July 28th, 2002, 05:32 PM
|
|
Gödelian monster
|
|
Join Date: Jul 1999
Location: Central Florida, USA
|
|
Or better yet (and easier) just have your two fields in your base table, and define a view that handles the calculation:
Define table:
Code:
CREATE TABLE mytable(
player varchar(32) NOT NULL, /* I'm guessing you'll want this */
goals int NOT NULL,
assists int NOT NULL
/* etc... any other columns you want... */
);
Define view:
Code:
CREATE VIEW vw_mytable AS
SELECT player, goals, assists,
(goals + assists) AS points
FROM mytable
ORDER BY player ASC;
This means whenever you change value in 'goals' or 'assists', you don't have to re-calculate a field. Any amount of calculations you want can be dealt with this way. Calculated fields in general should be avoided from base tables, because the proper place to handle them is usually in views. This is one of the rules of database normalization.
|