fra
fra

Reputation: 3858

SQL Server Persisted columns with value evaluated from function

Is it possible in Sql Server (2008, R2) to have a persisted column with a value resulting from a scalar function which queries other tables? I'm running into performance problems since I have a field that should be evaluated considering values coming from other tables. I logically solved the problem creating (indexed) views and evaluating the field using CASE WHEN, but now I'm running into performance issues with lot of data.

My idea is to evaluate the CASE WHEN in a function and use it as persisted column in the main table. Is it possible? Will changes in the views trigger an update of the value?

Can you suggest me alternative solutions (other than triggers)?

Thanks

Upvotes: 1

Views: 304

Answers (1)

podiluska
podiluska

Reputation: 51494

Even if it is possible, it's almost certainly a bad idea.

Triggers are there for a reason, and this is an ideal example. Why do you not want to use them?

Upvotes: 0

Related Questions