|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Today @ 6:34 AM
Points: 415,
Visits: 1,469
|
|
Hi All,
While reading about Computed column if found that if we mentioned PERSISTED Key word while creating/altering table then we can create index. But i'm able to create index with out that key word also.
By marking a computed column as PERSISTED, you can create an index on a computed column that is deterministic but not precise.
What i was thinking on difference between Computed column/Persisted computed column as if we create index on computed column then we can say that computed column as persisted column.
What is the need of computed column if we can do the same thing in the query/application? Can anybody give me such scenario where we must use this Computed column only?
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, June 13, 2013 7:03 AM
Points: 2,562,
Visits: 3,453
|
|
SQL* (1/23/2013) What is the need of computed column if we can do the same thing in the query/application?Can anybody give me such scenario where we must use this Computed column only? Lets take example of TAX table where
following are the column
Basic_salary HRA_Exemption SAving_80C saving_80CCC calulated_tax (computed column)
So whenever "Basic_salary ,HRA_Exemption,SAving_80C,saving_80CCC" gets populated the formula attached with caluated_tax column , will populated this column. NO application or query intervention required
-------Bhuvnesh---------- While 1 = 1 (Learning SQL....) Click to get fast response of your post
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Today @ 6:34 AM
Points: 415,
Visits: 1,469
|
|
 I got the importance of the Computed column, but what about other questions? PERSISTED/Creating Index on Calculated column.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 10:16 AM
Points: 1,092,
Visits: 7,931
|
|
SQL* (1/23/2013) Hi All,
While reading about Computed column if found that if we mentioned PERSISTED Key word while creating/altering table then we can create index. But i'm able to create index with out that key word also.
By marking a computed column as PERSISTED, you can create an index on a computed column that is deterministic but not precise.
There's no need to make the column persisted prior to indexing it.
I'm assuming you're referring to the text here. It reads like it's been copied out of context from somewhere else and the real meaning has been lost as a result.
I suspect it's really referring to computed columns that are deterministic, but imprecise (usually based on CLR functions), but I can see why you're confused.
This documentation has a more complete explanation of the imprecise computed column requirements :
http://msdn.microsoft.com/en-us/library/ms189292.aspx#BKMK_persisted
You can create an index on a computed column that is defined with a deterministic, but imprecise, expression if the column is marked PERSISTED in the CREATE TABLE or ALTER TABLE statement. This means that the Database Engine stores the computed values in the table, and updates them when any other columns on which the computed column depends are updated. The Database Engine uses these persisted values when it creates an index on the column, and when the index is referenced in a query. This option enables you to create an index on a computed column when Database Engine cannot prove with accuracy whether a function that returns computed column expressions, particularly a CLR function that is created in the .NET Framework, is both deterministic and precise.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 10:11 AM
Points: 1,333,
Visits: 1,803
|
|
HowardW (1/24/2013)
SQL* (1/23/2013) Hi All,
While reading about Computed column if found that if we mentioned PERSISTED Key word while creating/altering table then we can create index. But i'm able to create index with out that key word also.
By marking a computed column as PERSISTED, you can create an index on a computed column that is deterministic but not precise.
There's no need to make the column persisted prior to indexing it.
That's not necessarily always true. You might persist a column if its requires significant overhead to generate the value.
SQL DBA,SQL Server MVP('07, '08, '09) One man with courage makes a majority. Andrew Jackson
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 10:16 AM
Points: 1,092,
Visits: 7,931
|
|
ScottPletcher (1/24/2013)
HowardW (1/24/2013)
There's no need to make the column persisted prior to indexing it.
That's not necessarily always true. You might persist a column if its requires significant overhead to generate the value.
I think you've misunderstood my comment. You need to read the whole sentence, including the bit I've highlighted. Whether it's persisted via an index or in the column definition, it's still only calculated on modification.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 10:11 AM
Points: 1,333,
Visits: 1,803
|
|
HowardW (1/24/2013)
ScottPletcher (1/24/2013)
HowardW (1/24/2013)
There's no need to make the column persisted prior to indexing it.
That's not necessarily always true. You might persist a column if its requires significant overhead to generate the value. I think you've misunderstood my comment. You need to read the whole sentence, including the bit I've highlighted. Whether it's persisted via an index or in the column definition, it's still only calculated on modification.
I don't think you're thinking clearly about this. If it's not persisted, it has to be computed every time it's SELECTed or otherwise referenced. If that computation is a lot of overhead, it can be worthwhile to instead persist the computed value, especially if it's referenced frequently.
SQL DBA,SQL Server MVP('07, '08, '09) One man with courage makes a majority. Andrew Jackson
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 10:16 AM
Points: 1,092,
Visits: 7,931
|
|
ScottPletcher (1/24/2013)
HowardW (1/24/2013)
ScottPletcher (1/24/2013)
HowardW (1/24/2013)
There's no need to make the column persisted prior to indexing it.
That's not necessarily always true. You might persist a column if its requires significant overhead to generate the value. I think you've misunderstood my comment. You need to read the whole sentence, including the bit I've highlighted. Whether it's persisted via an index or in the column definition, it's still only calculated on modification. I don't think you're thinking clearly about this. If it's not persisted, it has to be computed every time it's SELECTed or otherwise referenced. If that computation is a lot of overhead, it can be worthwhile to instead persist the computed value, especially if it's referenced frequently.
Nope, I think you're not thinking clearly. How an earth would an index be able to be used if the key column was calculated on the fly during a select? Indexing a computed column persists it regardless of whether the column is marked as persisted in its definition.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 10:11 AM
Points: 1,333,
Visits: 1,803
|
|
HowardW (1/24/2013)
ScottPletcher (1/24/2013)
HowardW (1/24/2013)
ScottPletcher (1/24/2013)
HowardW (1/24/2013)
There's no need to make the column persisted prior to indexing it.
That's not necessarily always true. You might persist a column if its requires significant overhead to generate the value. I think you've misunderstood my comment. You need to read the whole sentence, including the bit I've highlighted. Whether it's persisted via an index or in the column definition, it's still only calculated on modification. I don't think you're thinking clearly about this. If it's not persisted, it has to be computed every time it's SELECTed or otherwise referenced. If that computation is a lot of overhead, it can be worthwhile to instead persist the computed value, especially if it's referenced frequently. Nope, I think you're not thinking clearly. How an earth would an index be able to be used if the key column was calculated on the fly during a select? Indexing a computed column persists it regardless of whether the column is marked as persisted in its definition.
Of course indexing requires persisting. I thought everyone was clear on that.
But you claimed, in your first quote above, there was no (never a) need to persist except to index. That's simply not true. Even if a computed column is not indexed in any way, there are times when it's still worthwhile to persist it to avoid re-computing it.
SQL DBA,SQL Server MVP('07, '08, '09) One man with courage makes a majority. Andrew Jackson
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 10:16 AM
Points: 1,092,
Visits: 7,931
|
|
ScottPletcher (1/24/2013)
Of course indexing requires persisting. I thought everyone was clear on that.
But you claimed, in your first quote above, there was no (never a) need to persist except to index. That's simply not true. Even if a computed column is not indexed in any way, there are times when it's still worthwhile to persist it to avoid re-computing it.
Right, OK, I see where the confusion is now, even if I don't know where you think I said there's never a need to persist a computed column, except to index it. I certainly didn't claim that, hence why I pointed out that you misunderstood my comment. If that was what I wanted to say, I would have said:
"There's no need to make the column persisted except to index it"
But what I said (and highlighted again after your comment) was:
There's no need to make the column persisted prior to indexing it.
As in, there's no requirement to persist the column before indexing it.
|
|
|
|