Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Erland Sommarskog Newsgroups: comp.databases.ms-sqlserver Subject: Re: Cursor Question Date: Fri, 02 Dec 2011 12:35:43 +0100 Organization: Erland Sommarskog Lines: 30 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Injection-Info: mx04.eternal-september.org; posting-host="nBFDv6s1VJQDuF1w6hpX2A"; logging-data="13122"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+vmSjv/1mCjcCXRc7WarVt" User-Agent: Xnews/2006.08.24 Mime-proxy/2.1.c.0 (Win32) Cancel-Lock: sha1:CvuAwZGYfgSQ7gOi07U4r063NUo= Xref: x330-a1.tempe.blueboxinc.net comp.databases.ms-sqlserver:857 Travis Crow (noreply@invalid.org) writes: > If I declare a cursor with a "where clause", is that "where clause" > evaluated when I declare the cursor or when I open it? It depends on the type of cursor. There are four types: DYNAMIC, KEYSET, STATIC and FAST_FORWARD. If you have a dynamic cursor, the query is essentially evaluated each time you do FETCH. That is, rows that are added to the table while the cursor is running will be visible. With a static cursor, the result set of the cursor is saved to a temp table and the rows are served from this table. I believe this happens at OPEN time, but you could easily test to find out. With a keyset cursor, only the keys are saved to the table, and remaining rows are read from the real table at FETCH. With FAST_FORWARD, I don't even know what happens. I strongly recommend to stick with STATIC cursors. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Links for SQL Server Books Online: SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx