all groups > sql server programming > april 2004 >
You're in the

sql server programming

group:

Cursor for self insertion


Cursor for self insertion Kishor
4/6/2004 10:01:03 PM
sql server programming: Hi

I am having a simple question related to the cursor, as I am not too much familiar with cursor

In my stored proc, I am using cursor for self-insertion and self-updations. Cursor is based on one basetable where I am making insertion and same time updations in one of the columns of the row based on current location.

But while executing this proc if some other user inserts rows in a table what will happen to that data?. will cursor fetch these newly added recs and process? Or do I need to execute the SP again

Please let me know

Kishor
Re: Cursor for self insertion Jason Zhou
4/6/2004 11:38:27 PM
Try use 'insensitive' when declare cursor, then you won't be affected by new
inserted or updated data.

Jason


[quoted text, click to view]
self-updations. Cursor is based on one basetable where I am making
insertion and same time updations in one of the columns of the row based on
current location.
[quoted text, click to view]
what will happen to that data?. will cursor fetch these newly added recs and
process? Or do I need to execute the SP again.
[quoted text, click to view]

Re: Cursor for self insertion Joe Celko
4/7/2004 9:51:10 AM
[quoted text, click to view]
self-updations. Cursor is based on one basetable where I am making
insertion and same time updations in one of the columns of the row based
on current location. <<

The short answer is that it depends on your isolation level and cursor
sensitivity.

The right answer is that you should not be writing code with cursors at
all if you know what you are doing. I am 99.99998% certain that you can
use pure SQL to get a huge increase in performance, portable code and
better maintainability.

Post the actual problem, with DDL, and see if anyone can help you find
the right answer to the problem instead of a procedural, proprietary
kludge.

--CELKO--
===========================
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.

*** Sent via Developersdex http://www.developersdex.com ***
AddThis Social Bookmark Button