November 8, 2012 at 5:04 am
is there any difference in using cursor and table ?
any performance issues ?
sample are shown below
example 1:
declare rs_cursor CURSOR for select name from master.dbo.sysdatabases
example 2:
DECLARE @temp as table (RowID int not null primary key identity(1,1),
Filename varchar(500))
insert into @temp select name from master.dbo.sysdatabases
November 8, 2012 at 5:09 am
Yes there is typically a huge difference depending on what you want to do.
Cursors are typical RBAR meaning it processes a row at a time, where as with a table it can process a "set" of data at a time which is more effective.
November 8, 2012 at 1:45 pm
^ This, and they're usually not compared to each other, as they have totally different uses. What you mentioned is a table variable and is more aptly compared to a temp table, while cursors to while loops. You can use a cursor on a temp table, to do a per-row transaction/DML, but not vice versa. A good analogy would be like comparing a subject with an adjective.
November 8, 2012 at 8:34 pm
is it possible to fetch multiple columns (using cursor)
November 8, 2012 at 10:21 pm
sumith1andonly1 (11/8/2012)
is it possible to fetch multiple columns (using cursor)
Yes it is possible to fetch multiple columns using cursors. You need to do a little research on Cursors.....the following link would help you a lot:
November 8, 2012 at 11:54 pm
sumith1andonly1 (11/8/2012)
is it possible to fetch multiple columns (using cursor)
Let's be clear here:
cursors are sloooooooooooow.
Only use them if you have a very good reason to use them.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
November 9, 2012 at 2:25 am
Koen Verbeeck (11/8/2012)
sumith1andonly1 (11/8/2012)
is it possible to fetch multiple columns (using cursor)Let's be clear here:
cursors are sloooooooooooow.
Only use them if you have a very good reason to use them.
Yes, I agree. Cursors are slow because they do row by row transactions instead of set based transactions which are much much much faster than row by row transactions.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply