﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by VM  / Persisted vs Non-persisted Computed columns / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 17:21:18 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>Nice question, I appreciate the intent of the question as I see it, 'Persisted does not mean permanent.'</description><pubDate>Wed, 20 Oct 2010 08:50:14 GMT</pubDate><dc:creator>timothy bates</dc:creator></item><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>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'--If I wanted to find all those who received a work permit on a give day, this query works but shows a table scan.SELECT [DOWorkPermit] FROM [Employee_2] WHERE [DOWorkPermit] = '12/31/1993';--Add an index on the persisted, computed column:CREATE NONCLUSTERED INDEX IX_WorkPermit ON [Employee_2] ([DOWorkPermit]);GO--The query still shows a table scan because DOBirth is in the output list and is needed to find the computed DOWorkPermit day:SELECT [DOWorkPermit] FROM [Employee_2] WHERE [DOWorkPermit] = '12/31/1993';-- drop and recreate the index including the DOBirth columnDROP INDEX IX_WorkPermit ON [Employee_2];GOCREATE NONCLUSTERED INDEX IX_WorkPermit ON [Employee_2] ([DOWorkPermit]) INCLUDE ([DOBirth]);GO--an index scan is now usedSELECT [DOWorkPermit] FROM [Employee_2] WHERE [DOWorkPermit] = '12/31/1993'My question is, couldn't an index seek be done on the persisted, indexed value rather than having to compute it while doing a scan?  Is it because there's only 1 record in the table or am I missing or misinterpreting something...</description><pubDate>Thu, 07 Oct 2010 11:25:33 GMT</pubDate><dc:creator>rtelgenhoff</dc:creator></item><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>[quote][b]Nils Gustav Stråbø (10/7/2010)[/b][hr]You won't believe how many people that actually use NOLOCK or READ_UNCOMMITTED to "fix" concurrency and locking problems. One of our vendors use NOLOCK in every(!) SELECT statement in a system we have purchased from them. They have never bothered to explain the reason for doing it, but my guess, after doing some investigation, is that it is caused by two things:- Lots of missing indexes, which results in excessive scans- Bad programming, because when I save data in the front-end, SQL Profiler showed that before the transaction for the update statement was committed, another connection from my pc was opened trying to read the updated row(s).[/quote]I worked as a consultant on a system for a major health insurance company and they had the nolock hint on every single query in their system. Keeping in mind that this is the system that pays disbursements both from "paper" claims and real time debit cards our balances were always out of whack because we would authorize payment when there was not enough money due to dirty reads. I can't tell you how many times I suggested that they should find better ways of dealing of locked tables. :w00t:</description><pubDate>Thu, 07 Oct 2010 07:47:45 GMT</pubDate><dc:creator>Sean Lange</dc:creator></item><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>Ok, I can see that my comment about using NOLOCK to fix concurrency issues could be explained a bit better, and that there are legitimate reasons to use it, for example in reporting scenarios.But I cannot see where I completely condemn the use of NOLOCK. I mentioned that one of our vendors use in in ALL SELECT statements, and most of them has nothing to do with reporting functionality. They are plain SELECTS that returns just a few rows, but because the client app is poorly programmed (as I tried to explain) the have "fixed" it with NOLOCK.</description><pubDate>Thu, 07 Oct 2010 07:29:22 GMT</pubDate><dc:creator>Nils Gustav Stråbø</dc:creator></item><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>[quote]HugoMostly queries that report aggregated data for an audience that doesn't care about the exact number, but only wants an indication. If the numbers my query produces will be rounded to the nearest million dollars anyway, I can live with a result that might be a couple of thousand dollars off. [/quote]Completely agree, which is why we unfortunately use it everywhere. Our environment is very large and growing. We literally have several thousand users hitting against the OLTP databases making hourly decisions. Unfortunately we are unable to replicate all of the necessary data to other locations for them to review though it is moved to a warehouse daily which is used primarily for trending as well as market basket and many other things. Reports are happening at the same time as OLTP. I appologize if you felt that I was picking, but I just wanted to get you to expand upon your answer. Thank you.[quote]NilsDid I ever say that this hint was never to be used? For reporting purposes where the possibility of reading dirty data does not affect the quality of the report then go ahead and use it. I've done it myself many times. What I mentioned in my previous post was misuse due to poor programming. [/quote]Unfortunately, your initial posting read very definite and you posted the 2 reasons that you felt were the the use of locking hints. If I misread, I am sorry - but how many others?</description><pubDate>Thu, 07 Oct 2010 07:14:47 GMT</pubDate><dc:creator>sjimmo</dc:creator></item><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>Nice questionI am much afraid by seeing the questionpost this type questions</description><pubDate>Thu, 07 Oct 2010 07:11:36 GMT</pubDate><dc:creator>Sree Arjun Div</dc:creator></item><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>Good question.....lots of reading first thing in the AM.</description><pubDate>Thu, 07 Oct 2010 06:58:10 GMT</pubDate><dc:creator>Daniel Bowlin</dc:creator></item><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>Did I ever say that this hint was never to be used? For reporting purposes where the possibility of reading dirty data does not affect the quality of the report then go ahead and use it. I've done it myself many times. What I mentioned in my previous post was misuse due to poor programming.</description><pubDate>Thu, 07 Oct 2010 06:42:36 GMT</pubDate><dc:creator>Nils Gustav Stråbø</dc:creator></item><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>[quote][b]sjimmo (10/7/2010)[/b][hr][quote]HugoShame about the (nolock) hints, though. They serve no purpose, and they might lead people to believe that these hints are okay to use. They are not, except in a very limited amount of situations. [/quote]What would these limited situations be?[/quote]Mostly queries that report aggregated data for an audience that doesn't care about the exact number, but only wants an indication. If the numbers my query produces will be rounded to the nearest million dollars anyway, I can live with a result that might be a couple of thousand dollars off.</description><pubDate>Thu, 07 Oct 2010 06:39:47 GMT</pubDate><dc:creator>Hugo Kornelis</dc:creator></item><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>First - this was a very good question. Learned something today which is great.[quote]HugoShame about the (nolock) hints, though. They serve no purpose, and they might lead people to believe that these hints are okay to use. They are not, except in a very limited amount of situations. [/quote]What would these limited situations be?[quote]NilsYou won't believe how many people that actually use NOLOCK or READ_UNCOMMITTED to "fix" concurrency and locking problems. One of our vendors use NOLOCK in every(!) SELECT statement in a system we have purchased from them. They have never bothered to explain the reason for doing it, but my guess, after doing some investigation, is that it is caused by two things:- Lots of missing indexes, which results in excessive scans- Bad programming, because when I save data in the front-end, SQL Profiler showed that before the transaction for the update statement was committed, another connection from my pc was opened trying to read the updated row(s). [/quote]How about thousands of connections hitting against high volume OLTP databases that are also required for up to the minute reporting where replication is not an issue nor are dirty reads?There are times where hints are required. I may not like them as the norm, but I don't think that one should dismiss them all together.</description><pubDate>Thu, 07 Oct 2010 06:17:50 GMT</pubDate><dc:creator>sjimmo</dc:creator></item><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>[quote][b]Hugo Kornelis (10/7/2010)[/b][hr]and they might lead people to believe that these hints are okay to use. They are not, except in a very limited amount of situations.[/quote]You won't believe how many people that actually use NOLOCK or READ_UNCOMMITTED to "fix" concurrency and locking problems. One of our vendors use NOLOCK in every(!) SELECT statement in a system we have purchased from them. They have never bothered to explain the reason for doing it, but my guess, after doing some investigation, is that it is caused by two things:- Lots of missing indexes, which results in excessive scans- Bad programming, because when I save data in the front-end, SQL Profiler showed that before the transaction for the update statement was committed, another connection from my pc was opened trying to read the updated row(s).</description><pubDate>Thu, 07 Oct 2010 05:31:20 GMT</pubDate><dc:creator>Nils Gustav Stråbø</dc:creator></item><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>Nice question.I was afraid it was some trick question of some exotic behaviour of SQL Server (with the no lock hints and everything), but luckily common sense was enough to answer the question.</description><pubDate>Thu, 07 Oct 2010 04:33:04 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>Nice question, though maybe a bit too easy.Shame about the (nolock) hints, though. They serve no purpose, and they might lead people to believe that these hints are okay to use. They are not, except in a very limited amount of situations.</description><pubDate>Thu, 07 Oct 2010 04:27:39 GMT</pubDate><dc:creator>Hugo Kornelis</dc:creator></item><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>Argh didn't get it wrong because I didn't know the answer but rather because I can't seem to count this morining.:blush:</description><pubDate>Thu, 07 Oct 2010 03:56:16 GMT</pubDate><dc:creator>Ian Elliott</dc:creator></item><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>Just one question. What's the significance of the (nolock) hint? Could you argue that none of the answers could be guaranteed in the event of a dirty read? Cheers and many thanks for the question. GPO</description><pubDate>Thu, 07 Oct 2010 01:50:28 GMT</pubDate><dc:creator>GPO</dc:creator></item><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>Thanks for the question.</description><pubDate>Thu, 07 Oct 2010 00:34:01 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>Nice question, thanks.Though I think formatting the code into little sections, and including the commented select statements, makes it a little more confusing and harder to read than it could have been.</description><pubDate>Wed, 06 Oct 2010 21:03:12 GMT</pubDate><dc:creator>UMG Developer</dc:creator></item><item><title>Persisted vs Non-persisted Computed columns</title><link>http://www.sqlservercentral.com/Forums/Topic1000107-1495-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/questions/T-SQL/70956/"&gt;Persisted vs Non-persisted Computed columns&lt;/A&gt;[/B]</description><pubDate>Wed, 06 Oct 2010 21:01:55 GMT</pubDate><dc:creator>VM-723206</dc:creator></item></channel></rss>