47.Cursor in SQL|While Loop Vs Cursor|Which is Better for Performance? Performance Tuning Concept

Опубликовано: 09 Октябрь 2024
на канале: Pandey Guruji
1,568
21

This Video contains In-depth coverage of Cursor in SQL|While Loop Vs Cursor|Which is Better for Performance? Performance Tuning Concept. Covers all of the important queries and SQL commands. In this videos series, you'll learn how to read and write complex queries. Handle tricky SQL interview questions. Implement complex SQL queries and answer popular interview questions on SQL. These videos series will help to crack interviews and get jobs in SQL Developer, Database Developer, Data Engineer, Reporting Analyst, Data Analyst, Data Scientist, System Analyst, Power BI Developer, Tableau Developer, BI Developer, etc.
-----------------------------------------------------------------------------------------------------------------
Real-time one-to-one training, Enroll Now: https://pandeyguruji.graphy.com/
Free training materials: https://t.me/pandeyguruji
For any queries contact me on social media:
Facebook:   / mpandeyguruji  
Instagram:   / pandey_guruji  
Linkedin:   / mukesh-pandey-1a151634  
Q&A Session: https://t.me/+Mtp3M1b_nXc3YjE9
-------------------------------------------------------------------------------------------------------------------
SQL Tutorial for Beginners in Hindi: https://bit.ly/3CwfnGB
SQL Tutorial for Beginners in English: https://bit.ly/3qVI3GQ
SQL Live Training: https://bit.ly/3kXqOl1
Crack SQL Interview: https://bit.ly/3caxIyb
SQL Interview Questions: http://bit.ly/2CR6wCZ
Advance SQL Interview Questions: https://bit.ly/3HnMrnN
Career Guidance: https://bit.ly/3FffkRf
IT Technology News & Updates: https://bit.ly/3FeNQvc
--------------------------------------------------------------------------------------------------------------------
WHAT IS CURSOR?
A cursor is a database object which is used to retrieve data from result set one row at a time. The cursor can be used when the data needs to be updated row by row.
Types of Cursors in SQL:
Implicit Cursor
Explicit Cursor
Implicit Cursor: Whenever DML operations such as INSERT, UPDATE, and DELETE are processed in the database, implicit cursors are generated automatically and used by the framework. These types of cursors are used for internal processing and can’t be controlled or referred from another code area.
Explicit Cursor: This type of cursor is generated whenever data is processed by a user through an SQL block. Generally, the use of the SELECT query triggers the creation of an explicit cursor and can hold more than one row but process just one at a time.
CURSOR LIFE CYCLE: Declaring CursorA cursor is declared by defining the SQL statement.
Opening CursorA cursor is opened for storing data retrieved from the result set.
Fetching CursorWhen a cursor is opened, rows can be fetched from the cursor one by one or in a block to do data manipulation.
Closing CursorThe cursor should be closed explicitly after data manipulation.
Deallocating CursorCursors should be deallocated to delete cursor definition and released all the system resources associated with the cursor.

WHY USE CURSORS?In relational databases, operations are made on a set of rows. For example, a SELECT statement returns a set of rows which is called a result set. Sometimes the application logic needs to work with a row at a time rather than the entire result set at once. This can be done using cursors.
CURSOR LIMITATIONSA :cursor is a memory resident set of pointers -- meaning it occupies memory from your system that may be available for other processes.

The cursors are slower because they update tables row by row.
#Cursor, #PerformanceTuningInSQL, #PandeyGuruji