Тёмный

Cursors in sql server Part 63 

kudvenkat
Подписаться 836 тыс.
Просмотров 439 тыс.
50% 1

Text version of the video
csharp-video-tu...
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our RU-vid channel. Hope you can help.
/ @aarvikitchen5572
Slides
csharp-video-tu...
All SQL Server Text Articles
csharp-video-tu...
All SQL Server Slides
csharp-video-tu...
All Dot Net and SQL Server Tutorials in English
www.youtube.co...
All Dot Net and SQL Server Tutorials in Arabic
/ kudvenkatarabic
Relational Database Management Systems, including sql server are very good at handling data in SETS. For example, the following "UPDATE" query, updates a set of rows that matches the condition in the "WHERE" clause at the same time.
Update tblProductSales Set UnitPrice = 50 where ProductId = 101
However, if there is ever a need to process the rows, on a row-by-row basis, then cursors are your choice. Cursors are very bad for performance, and should be avoided always. Most of the time, cursors can be very easily replaced using joins.
There are different types of cursors in sql server as listed below. We will talk about the differences between these cursor types in a later video session.
1. Forward-Only
2. Static
3. Keyset
4. Dynamic
Let us now look at a simple example of using sql server cursor to process one row at time. We will be using tblProducts and tblProductSales tables, for this example. On my machine, there are 400,000 records in tblProducts and 600,000 records in tblProductSales tables. If you want to learn about generating huge amounts of random test data, please watch Part - 61 in sql server video tutorial. The link is below.
www.youtube.com...
Cursor Example: Let us say, I want to update the UNITPRICE column in tblProductSales table, based on the following criteria
1. If the ProductName = 'Product - 55', Set Unit Price to 55
2. If the ProductName = 'Product - 65', Set Unit Price to 65
3. If the ProductName is like 'Product - 100%', Set Unit Price to 1000
For the SQL code samples used in the demo please visit my blog at the following link
csharp-video-tu...
The cursor will loop thru each row in tblProductSales table. As there are 600,000 rows, to be processed on a row-by-row basis, it takes around 40 to 45 seconds on my machine. We can achieve this very easily using a join, and this will significantly increase the performance. We will discuss about this in our next video session.
To check if the rows have been correctly updated, please use the following query.
Select Name, UnitPrice
from tblProducts join
tblProductSales on tblProducts.Id = tblProductSales.ProductId
where (Name='Product - 55' or Name='Product - 65' or Name like 'Product - 100%')

Опубликовано:

 

16 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 92   
@ranikala2395
@ranikala2395 8 лет назад
great.thank you.clear,simple code
@Csharp-video-tutorialsBlogspot
+Rani Kala Thank you so much for the feedback. Means a lot. Glad the videos are useful. Dot Net & SQL Server training videos for aspiring web developers ru-vid.complaylists?view=1&sort=dd Download our training videos and slides for offline viewing www.pragimtech.com/Order.aspx Code Samples, Text Version of the videos & PPTS on my blog csharp-video-tutorials.blogspot.com Tips to best utilise our channel ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-y780MwhY70s.html To receive email alerts, when new videos are uploaded, please subscribe to our channel using the link below ru-vid.com Please click the THUMBS UP button below the video, if you think you liked them Thank you for sharing the link with your friends who you think would also benefit from them Best Venkat
@zeyonghuang8133
@zeyonghuang8133 7 лет назад
i am chinese ,i come from china. i have not been to any other country. i just like to use vpn to visit google or youtube ,studying some technology. our chinese people said ,proctect my country ,Not allowed to use vpn. our teachers can not teach like these videos which are very useful and very clearly. i am sad, and maybe in the next hour,i can not visit youtube.
@huslerbling
@huslerbling 9 лет назад
You're an excellent teacher. I only watch your videos now and I subscribed! keep it up!
@rolikaseventysix
@rolikaseventysix 5 лет назад
Pointer to resultset, this is the most important thing, that explains cursors to a programmer at once. Thanks for the video.
@krzysztofs8535
@krzysztofs8535 7 лет назад
Great difficult code, but it works. I'm going fast to the next video session. U are great teacher. I've improved new skills thankx to U. Greetings from Poland.
@barbaraulitsky9055
@barbaraulitsky9055 3 года назад
This video was very helpful for me and it's very neat and organized. Thank you so much!!!
@waelalghazouli8024
@waelalghazouli8024 3 года назад
Thank you very much, amazing explanation as always!
@prachibelose1595
@prachibelose1595 7 лет назад
Your videos have always been my "go to" resource for SQL
@AnkitSharma-pt8cq
@AnkitSharma-pt8cq 8 лет назад
Great Explanation , Your videos are very useful . Thanks
@barbaraulitsky9055
@barbaraulitsky9055 5 лет назад
Thank you for sharing! This video is very helpful for my work!
@anilgarlapati8998
@anilgarlapati8998 8 лет назад
U are a great teacher ..
@fresh_meadow_mansi9843
@fresh_meadow_mansi9843 3 года назад
Thank you for this brilliant course on sql,you are life saver .
@travismills5400
@travismills5400 3 года назад
Great explanation of Cursors! I appreciate this.
@babzo1
@babzo1 10 лет назад
Thanks Venkat .You are the man. Looking forward to more insightful tutorials from you .And please talk about the execution plans .Cheers
@Csharp-video-tutorialsBlogspot
@Csharp-video-tutorialsBlogspot 11 лет назад
Hi Jason, I almost forgot about it. Yet to record. Thanks for reminding. Will do it as soon as I can.
@krisid8313
@krisid8313 Год назад
Great job at explaining cursors!!
@btoz6237
@btoz6237 4 года назад
Great simple and easy to understand video about cursors. Keep up the great work my friend!
@pramodmaurya6610
@pramodmaurya6610 5 лет назад
Thanks for your knowledge sharing.. thanks a lot sir
@kevingarner7231
@kevingarner7231 10 лет назад
Another great video by Venkat!
@Funblog1024
@Funblog1024 Год назад
after very long of search find a useful video for cursor .
@mr.prasadyadav
@mr.prasadyadav 4 года назад
Great Lecture simply you are Best that's it sir
@ranweerkumar180
@ranweerkumar180 4 года назад
Sir what is difference between cursor and while loop, why we use while inspite of using cursor.
@lavanyaarumugam4055
@lavanyaarumugam4055 9 лет назад
Hi Sir, Your videos and way of expressing it is really awesome..Please kindly give videos on dynamic SQL ..
@Csharp-video-tutorialsBlogspot
@Csharp-video-tutorialsBlogspot 11 лет назад
Sure, Anurag, will do it as soon as I can.
@shivaniprajapati9899
@shivaniprajapati9899 6 лет назад
HELLO Sir Your videos are very beneficial for freshers.... M alwys watching ur videos and recommended to all my frndzzz....
@viralcb
@viralcb 11 лет назад
Very good job brother..I am following all of your videos..please keep doing this.
@jasonleelawlight
@jasonleelawlight 11 лет назад
Thank you sir! I have watched all the videos in this list and I look forward to your new videos.
@teaMmMate
@teaMmMate 7 лет назад
Thanks for the lesson, it really helped with my project. Much appreciated!
@lavanyaarumugam4055
@lavanyaarumugam4055 9 лет назад
Thank you so much for your efforts for us.
@satheeshkumarsuthari705
@satheeshkumarsuthari705 10 лет назад
Dear Venkat..awesome work really...but can you upload oracle sql and plsql...!!!you are uploading just microsoft server concepts..but we need oracle concepts as well please...thanks
@Csharp-video-tutorialsBlogspot
@Csharp-video-tutorialsBlogspot 11 лет назад
Thank you very much for taking time to give feedback. I upload training videos on a daily basis. If you want to receive email alerts when new videos are uploaded, please feel free to subscribe to my youtube channel.
@madaysvlogsandtalks5766
@madaysvlogsandtalks5766 6 лет назад
hi sir,I have a doubt.plz clarify my doubt. In column data that contains data like country(SL001) like this data is stored bt now I want only country I don't want code which contains in braces for multiple record which code contain 'SL'
@madaysvlogsandtalks5766
@madaysvlogsandtalks5766 6 лет назад
how to write a query for that to update all the records at a time
@crapscrapentertainment-pow7898
@crapscrapentertainment-pow7898 4 года назад
Excellent tutorial, thank you 👍
@TheGuroguro12
@TheGuroguro12 7 лет назад
Thank you very much very good explanation .
@visionfromabove769
@visionfromabove769 7 лет назад
brilliant and a clear guide, thank you for this
@rounaksinghbuttar9083
@rounaksinghbuttar9083 9 месяцев назад
This really helped, thank you.
@harveywang4094
@harveywang4094 3 года назад
Great teaching, indeed
@davelb54
@davelb54 7 лет назад
I know it's been a long time since your SQL Server videos 63 and 64 were published, but I was wondering how I would go about coding the original cursor example in video 63 (printing the product id and product name for the rows in the database) using a set-based/joins approach instead of a cursor.
@bhavyar2986
@bhavyar2986 3 года назад
great video... why two times fetch statement?
@Rahu353
@Rahu353 11 лет назад
Very good one Venkat...
@ZhuShisubi
@ZhuShisubi 4 года назад
Okay since it's advised to write set based queries in SQL, why ever use a cursor? When will I need a row by row query?
@chandrashekhardhakate3395
@chandrashekhardhakate3395 6 лет назад
Thank you sir..for giving us good concept
@dianex.3544
@dianex.3544 6 лет назад
Excellent tutorial! Thank you!
@sridharaphyd
@sridharaphyd 8 лет назад
Hi. Nice videos. Could u upload video about "execution plan" in sql server. If already it is uploaded plz send me the link. I watched almost all videos but I did not found. Thank u
@jasonleelawlight
@jasonleelawlight 11 лет назад
Hi Venkat, your explanation is awesome! I have a quick question, in the previous video you said you would talk about how to read the execution plans etc., but the topic of this video is obviously different, so is it that you have not made that video yet or that you have not uploaded it on youtube yet? Thank you!
@jeremyvillar7899
@jeremyvillar7899 3 года назад
god bless this man
@pushkarraj6297
@pushkarraj6297 5 лет назад
Thank you sir.. sir, what is scroll keyword sometimes seen in declare statement???
@kunnudev7250
@kunnudev7250 4 года назад
Great job
@universeapps2835
@universeapps2835 3 года назад
u're the best thanks
@user-rp9iis1en6h
@user-rp9iis1en6h 3 года назад
Hi Venkat, Let's say I have a table containing 100k rows and sometimes I need to delete 10k rows at a time using their id. From c# I can pass the list of ids or I can call a delete store proc with id parameter that will delete row one by one. Is there any better way to perform something like bulk delete with high performance?
@aakutotaharika9160
@aakutotaharika9160 11 лет назад
hi venkat can u explain if...exists....in stored procedure and how to send mails regarding events before 3 working days.Events are in database..
@ro_tec
@ro_tec 10 месяцев назад
Thank you very much sir ❤
@dineshp3296
@dineshp3296 6 лет назад
Nice explanation thanks...
@maryam4071
@maryam4071 4 года назад
great video. I don't get how outer cursor is looping row by row, when there is no while loop?
@debarghyachakraborty
@debarghyachakraborty 4 года назад
Outer cursor isn't looping it is just getting into table by 'FETCH NEXT', through it control is getting into the inner while loop.
@SrinivasaKalyanParupalli
@SrinivasaKalyanParupalli 10 лет назад
You are amazing man.. Why weren't you available in my Uni :). This sort of stuff makes RU-vid proud. Keep it up
@yangshek3277
@yangshek3277 Год назад
well explained!!
@kiranhyde
@kiranhyde 10 лет назад
Hi Venkat, Can you please add a video for differences between cursor types
@addy2954
@addy2954 Год назад
wow, 8 years ago man!!!
@parthparth8680
@parthparth8680 2 года назад
GOOD EXPLAINATION
@adimatanmalul5790
@adimatanmalul5790 2 года назад
very clear! thanks a lot =)
@2divyanshu
@2divyanshu 8 лет назад
thank u !!!
@keerthik2993
@keerthik2993 4 года назад
Hello venkat, I want to learn pl/sql programming from you. Could u please tell me how I can contact you? Thank you
@debarghyachakraborty
@debarghyachakraborty 4 года назад
Contact his institution Pragim Technologies at www.pragimtech.com
@Shahriar_Firoz
@Shahriar_Firoz 6 лет назад
Question: Everywhere they say not to use Cursor as it causes high compilation time and parse of the fetch statements and also there are other quicker ways to obtain same results using joins. Then, why is Cursor an option for querying in SQL server? Is there any specific reason to only use Cursor for any particular query? Will appreciate anyone who clarify this for me. :)
@ZhuShisubi
@ZhuShisubi 4 года назад
Because SQL is designed for Set Base operations and not for looping, the cursor should be deprecated but it remains because more than likely bad programmers will go ape shit. I have never needed to use one.
@SonNguyen-fm3hh
@SonNguyen-fm3hh 6 лет назад
Thanks for the Videos, it's Awesome :D
@roopalityagi3958
@roopalityagi3958 5 лет назад
can we use select statement in while loop ? i was asked this question in sql developer interview
@nishanthgaddam8426
@nishanthgaddam8426 4 года назад
Yes we can use it.
@couragemath9333
@couragemath9333 6 лет назад
good job. thank you.
@ah.sin4
@ah.sin4 3 года назад
Thank you
@mitwa1990
@mitwa1990 11 лет назад
Awesome job...Keep it up bro!!!
@n70amu
@n70amu 7 лет назад
Sir very nice tutorial, can we download the database for practice please?
@bizzar31
@bizzar31 11 лет назад
you are awesome sir
@wingsumlo7170
@wingsumlo7170 6 лет назад
Well explained
@ravids5497
@ravids5497 4 года назад
Hello plz help me, I'm getting unknown system variable @@FETCH_STATUS. HOW TO RESOLOVE DIS??
@anup161091
@anup161091 2 года назад
It is not displaying anything it is just writing commands completed sucessfully. It is not displaying the result in your first query.
@paritoshsarkar5821
@paritoshsarkar5821 6 лет назад
really great
@oddnumber8149
@oddnumber8149 4 года назад
where is the data again??some times you have it
@samajad1
@samajad1 10 лет назад
thanx man .i learned a lot of things . thnxxxxxxxxxxxxxxxx a lot
@sureshrajput2147
@sureshrajput2147 7 лет назад
Hi Sir Please Upload video on collation.
@priyapandey-gf5oz
@priyapandey-gf5oz 4 года назад
How can I use cursor to insert record from one table to another and then mark the existing record as duplicate in previous table...can anybody guide me
@srilathareddy9414
@srilathareddy9414 5 лет назад
Please Can You Share The Video How to download and Install SSMS. I was download Many Times But It Was Not Work
@chetantherala
@chetantherala 5 лет назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-yasfZuou3zI.html follow this link and watch the video :)
@AkNpli
@AkNpli 6 лет назад
sir plz can u make one demo tool for migrating data from ms sql to oracle
@pallavhkust2298
@pallavhkust2298 7 лет назад
The red pulsing cursor is annoying. Simply use RED color cursor instead.
@sauravpanda3017
@sauravpanda3017 2 года назад
Do we have any replacement of bulk collect and fetchall in sql server as I don't want to have a loop for each record.
@maurobilotti
@maurobilotti 11 лет назад
Excellent explaination! Thank you!!
Далее
Replacing cursors using joins in sql server   Part 64
10:24
Stored procedures in sql server   Part 18
20:11
Просмотров 1,5 млн
Cole Palmer Revenge vs Man City 🥶
00:20
Просмотров 1,5 млн
Слушали бы такое на повторе?
01:00
SQL Cursors - how and when to use them
7:45
Просмотров 62 тыс.
SQL Server Programming Part 12 - Cursors
27:19
Просмотров 124 тыс.
Indexes in sql server   Part 35
11:13
Просмотров 839 тыс.
Stored procedures with output parameters   Part 19
18:20
Просмотров 782 тыс.
DML triggers in sql server   Part 43
17:45
Просмотров 691 тыс.
Subqueries in sql   Part 59
14:34
Просмотров 375 тыс.
Views in sql server   Part 39
14:51
Просмотров 592 тыс.