question

bhanupratapsngh9 avatar image
bhanupratapsngh9 asked

how to use computed columns

Respected Geeks, i am new to sql server i want little assistance regarding to storage planning like as i am working for a financial db. i am having a table create table dbloan (customerid int not null, memid tinyint not null, loanid tinyint not null, loanprovider varchar(150), loanamount money,) customerid + memid+loanid is composite key where loanid will start from 101 memid is storing memberid of a family. here i want to have calculation with other tables according to total of family , memberwise total of loanamount, should i use computed columns, or which strategy should i use i am totally confused looking for urgent assistance thanks in advance
computed-column
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Dave_Green avatar image
Dave_Green answered
If I am interpreting your need correctly, you want to store in table *dbloan* a total of related fields which are stored in other tables. Computed columns can be used to get results from other tables [using a function to calculate the required data][1], but this function will get executed each time the value is recalculated (and you wouldn't want to persist it as the data could change in other tables without an update to this one) so this may have an effect on performance. You could use a view to extract the results instead of querying the table directly. The plan for the view can be cached, but the total would be recalculated each time. A Stored Procedure could also be used to do this. You could look at manually maintaining a total in a data column, perhaps using triggers, but this is a little more effort, both for you to put it in place, and for the SQL server to update it after each write - which may result in more table locks in place for the update. I would look at the view option first, but this does depend upon your application. I would also explore how many queries which reference this table will require the information, and the performance impact of the options in your environment, as that may steer your strategy. [1]: http://stackoverflow.com/questions/9696687/define-a-computed-column-reference-another-table [2]: http://msdn.microsoft.com/en-us/library/ms191250.aspx
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.