Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Replacing cursors using joins in sql server   Part 64
Play lesson

SQL Server tutorial for beginners - Replacing cursors using joins in sql server Part 64

5.0 (5)
35 learners

What you'll learn

This course includes

  • 27 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

Text version of the video http://csharp-video-tutorials.blogspot.com/2013/01/replacing-cursors-using-joins-in-sql.html 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 YouTube channel. Hope you can help. https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation=1 Slides http://csharp-video-tutorials.blogspot.com/2013/09/part-64-replacing-cursors-using-joins.html All SQL Server Text Articles http://csharp-video-tutorials.blogspot.com/p/free-sql-server-video-tutorials-for.html All SQL Server Slides http://csharp-video-tutorials.blogspot.com/p/sql-server.html All Dot Net and SQL Server Tutorials in English https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd All Dot Net and SQL Server Tutorials in Arabic https://www.youtube.com/c/KudvenkatArabic/playlists In Part 63, we have discussed about cursors. The example, in Part 63, took around 45 seconds on my machine. Please watch Part 63, before proceeding with this video. In this video we will re-write the example, using a join. Update tblProductSales set UnitPrice = Case When Name = 'Product - 55' Then 155 When Name = 'Product - 65' Then 165 When Name like 'Product - 100%' Then 10001 End from tblProductSales join tblProducts on tblProducts.Id = tblProductSales.ProductId Where Name = 'Product - 55' or Name = 'Product - 65' or Name like 'Product - 100%' When I executed this query, on my machine it took less than a second. Where as the same thing using a cursor took 45 seconds. Just imagine the amount of impact cursors have on performance. Cursors should be used as your last option. Most of the time cursors can be very easily replaced using joins. To check the result of the UPDATE statement, 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%')

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

FAQs

Course Hive
Download CourseHive
Keep learning anywhere