Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Calculated fields performance

Author  Topic 

dmaxj
Posting Yak Master

174 Posts

Posted - 2008-10-29 : 00:48:05
I have 2 fields defined as datetime datatypes that are calculated . I am concerned about how the database will start to perform over time with these calculated fields once thousands of records are inserted.

My question: Is it possible to achieve the same values on the fly with a SQL script instead of using the calculated fields?

Each calc field is based on an EventDate. My calc fields are defined as (EventDate - 7) and (EventDate - 14).

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-29 : 00:51:45
yup.you can calacualte them on the fly. no need of keeping them in table. just use DATEADD(dd,-7,EventDate) and DATEADD(dd,-14,EventDate)
Go to Top of Page

bjoerns
Posting Yak Master

154 Posts

Posted - 2008-10-29 : 05:51:25
Note that there's two types of calculated fields:

By default they are not physically stored, but calculated when queried. So performance will be pretty much the same as calculated explicitely in your queries.

If you define them persisted, they are physically stored. So they must be calculated on inserts and updates. On the other hand, queries may run faster.

Go to Top of Page
   

- Advertisement -