Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
stan9186
Starting Member
7 Posts |
Posted - 2007-07-06 : 00:14:33
|
| Hi everyone...May I know what is Cursor is? Why and when we should use Cursor? How it improve the performance.. I have try to read some tutorial but still does not get it...I try to test this query but it returns the first rows.. How to use cursor actually?DECLARE authors_cursor CURSORFOR SELECT * FROM authorsOPEN authors_cursorFETCH NEXT FROM authors_cursorCLOSE authors_cursordeallocate authors_cursor |
|
|
sachinsamuel
Constraint Violating Yak Guru
383 Posts |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-07-06 : 01:18:00
|
"Why and when we should use Cursor? How it improve the performance?"cursors hardly ever improve performance. the only case I know of where they might is when calculating running totals.If you are new to sql, probably best to not even bother with them now - stick to the set-based ways of doing things. elsasoft.org |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-07-06 : 02:16:15
|
quote: Originally posted by stan9186 Hi everyone...May I know what is Cursor is? Why and when we should use Cursor? How it improve the performance.. I have try to read some tutorial but still does not get it...I try to test this query but it returns the first rows.. How to use cursor actually?DECLARE authors_cursor CURSORFOR SELECT * FROM authorsOPEN authors_cursorFETCH NEXT FROM authors_cursorCLOSE authors_cursordeallocate authors_cursor
First explain what you wantThen it can be decided if you need cursorMadhivananFailing to plan is Planning to fail |
 |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2007-07-06 : 06:20:33
|
| If you do insist on using cursors....you also need to include a "loop" construct, which allows you to get more than just the 1st record....(search here for example of cursors)But best advice...is stay away from them until absolutely necessary. |
 |
|
|
pootle_flump
1064 Posts |
Posted - 2007-07-06 : 08:30:37
|
| Another reason you might want to use them is for performing admin functions. Personally I can't be bothered learning the syntax so just use loops if I do need to process a set of data iteratively. |
 |
|
|
|
|
|