views:

183

answers:

2

One thing I want to do is build a personal database for myself at home to use a financial database (transaction log, checking/savings account tables, etc), and I want to do this mainly to learn more about developing databases. I am pretty familiary with MS Access, though not put to use in this context, but what I am really trying to learn is SQL Server.

SO, that being said, the first question that popped into my mind is that if I have a transactions table that I would want to use as a ledger, then is there some method to have the table automatically perform a calculation for one field (balance) based on another field(s) (expense, revenue fields)? Similiar to what someone may do with Excel......

Or is this something I would have to do with an unbound form, and an UPDATE statement kinda of approach?? if a table constraint exists for this type of idea, I would like to learn it....

I mentioned MS Access in the title, but a SQL Server is also most appreciated. Thanks for the help!

+1  A: 

In MS SQL server, you can use computed columns for this: http://msdn.microsoft.com/en-us/library/ms191250.aspx

Roland Bouman
thanks for the resource!!
Justin
+2  A: 

Derived data should not be stored except if it needs to be indexed -- you calculate the values in your SQL statements, or in the presentation layer.

In addition to computed columns in SQL Server tables, you can have them in VIEWS and you can index them. The term is "indexed view" and when you do that, the data is persisted in a hidden temp table and updated on the fly when the data the VIEW is derived from is changed. You can read about it under the TYPES OF VIEWS topic in the same link cited in @Roland Bouman's answer.

Last of all, it's not clear to me why you mention Access at all if you're using SQL Server as your back end. Are you developing your front end in Access?

David-W-Fenton
nope, just more experience in access, just learning SQL Server; that's all. thanks for the help!
Justin
If you're not developing your front end in Access, and you're using SQL Server as data store, what does Access have to do with your question?
David-W-Fenton
because this is something that I would have liked to learn in either Access or SQL Server....if such a technique existed. I read about the link below, but what you are saying about calcs in the presentation layer makes sense to me. I know how to work this idea several ways in Access, but SQL Server is something I have to learn yet. Though I am working on learning ASP.NET, visual studio, etc now. thanks
Justin