December 27, 2011 at 6:34 am
karthikeyan-444867 (12/27/2011)
LOOP ?WHILE LOOP ?
Loops are equally bad as cursors. You might only save few milliseconds (or microseconds).
December 27, 2011 at 9:13 am
karthikeyan-444867 (12/27/2011)
Thats what my first thought (using cursor) on this requirement. But...i just wanted to do this without using BAD CURSOR 🙁
The "badness" of a cursor is pretty mild compared to commiting non-atomic transactions, all things considered. You're trying to insert partial data and rollback partial data, and that's a violation of the whole ACID concept of transactional databases.
Avoiding a cursor in such a situation is like a doctor worrying about his patient getting a runny nose, while the patient has cancer.
So, don't worry about the cursor. Worry about the data structure, business rules, et al, that are causing you to break ACIDity in your database. That's a much more serious situation.
Build the insert with a correct Where clause, so it won't try to violate the PK. That'll fix both situations (the ACIDity of the transaction and the need for a cursor).
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
December 27, 2011 at 9:14 am
Dev (12/27/2011)
karthikeyan-444867 (12/27/2011)
LOOP ?WHILE LOOP ?
Loops are equally bad as cursors. You might only save few milliseconds (or microseconds).
And you might make it worse. While Loops are frequently slower than cursors.
Of course, comparing speed on them is kind of like arguing about which glacier is faster.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 3 posts - 16 through 17 (of 17 total)
You must be logged in to reply to this topic. Login to reply