开发者

Computed columns or store

I need a couple of computed columns that contain count totals (indexed columns). Do you think it is better to use a computed column in a view or add extra columns to the table that will store the totals? Adding extra columns would probably mean us开发者_JAVA百科ing triggers to keep the count totals correct.

DB is MS SQL 2008 R2.


You can use a indexed view to get the performance of stored columns at no maintenance effort.


It depends.

If the tables change a lot but you rarely need the counts, a view is better. The question "view vs. computed columns" is one of DB design. If you can't change the original table or the DBMS doesn't support computed columns, use a view. If you can change the table definition, computed columns can be better but they also clutter the definition and make select * slower if you don't always need this data.

If the table rarely changes but you need those numbers a lot, use extra columns with triggers to avoid performance problems.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜