SQL Cursors - how and when to use them

preview_player
Показать описание
In this video, I will show you how to create a cursor in SQL and explain when it should be used using an example.
Рекомендации по теме
Комментарии
Автор

So detailed and calmly-paced, absolute newbies at the end of this video should end up knowing 95% of all cursor practical uses. Period. Subscribed!

AlejandroBelloRD
Автор

In an SQL c lass and took a 0 on the Cursors assignment because I just couldn't wrap my head around it, and my instructor was no help. I wish I'd have watched this video, thanks for the perfect explanation!

ohiovstheworld
Автор

So fortunate to find exact scenario that fits my need. Thanx James.

qizstzr
Автор

We can just use summary of group by right? I still dont get the value for the cursor

muhajirikhsanushabri
Автор

I watched multiple videos about Cursors, finally I found the one that explains cursors in a simple way

The_abdelhafid
Автор

why not group the second table by account_number and calculate the sum of payments for each account number, first, then join this result of that with the balance table and subtract aggregated results?

paulfunigga
Автор

Fantastic video, if you keep making videos like this you will help a lot of people and find serious success.

jamesheyne
Автор

This is the clear explanation of why we have to use cursor. Thanks alot !

chammu
Автор

won yourself a suscriber just because of this video, huge props man

mngn
Автор

this is the first SQL tutorial i found on youtube which is not from an indian guy, thank you

drecksackblase
Автор

That’s awesome James . Definitely to use cursor . Thank you for sharing your knowledge. This is typical use case for cursor

owhbbuz
Автор

Nice & Smooth explanation.
well done.

shubhamsahu
Автор

You said that the payments data can be aggregated, but that is missing the point. But I think it is a great point, since after watching this video, I still don't know a case scenario where a cursor would be the best option. I would only use cursors as a last resort, since they perform poorly and complicates debugging.

satori
Автор

You've earned yourself a sub my friend

alexingino
Автор

You made my life easy .. thank you so much

saudhj
Автор

Thank you for explaining so clearly! Great walk through

danaewardrup
Автор

5Star to you. awesome comparison, finally found the real reason after so many years.

manoman
Автор

You have tastefully placed fast-forward segments when you type your code. Take my sub!!!

chaoticrealm
Автор

If anyone at my work used a cursor instead of just using SUM to perform this update I would fail their code review immediately and have a teaching session with them

Cursors can dynamically update if the source is updated mid update and can global depending on configuration unless you specify LOCAL FAST_FORWARD.

People also tend to use them to call stored procedures per row in triggers and more frequently then not, it has lead to more time fixing issues than time saved by that sole developer in having to think about a more adequate solution.

I've received multiple late night calls to fix performance issues where jobs stalled as a result of devs doing this kind of stuff

The only time I think I've actually seen a decent argument for cursors was for operating on DMV objects such as forcing index and more importantly statistics rebuilds and I'd bet you can still just do that with a while loop at the loss of ignoring changes during the loop firing (forcing it to be processed on the next call to that job)

I've literally wrote a temporally stable audit table code generator that generates

1. Audit table for a table
2. Audit Foreign Keys connecting Audit tables by AuditIDs in the same manner as the original table
3. Triggers for INSERT, UPDATE, and DELETE operations

And I STILL never needed to use a CURSOR.

If you're familiar with the idea of "bad parts" of a language such as "with" or "this" in JS it's the exact same concept.
You can write better code by constraining yourself to not use the bad parts of a language and Cursors are a horrible part of the SQL language

blazinghellwheels
Автор

Thank you so much, it is very helpful.

HauLe-svsy