A database cursor is a manipulate shape that permits traversal over the archives in a database.Cursor in MySQL is nearly the identical as a cursor in different databases. MySQL cursor is a form of loop facility given to traverse in the end result of SQL one by means of one. We can function on each end result by means of the usage of the cursor in MySQL. Cursors are supported in saved procedures, functions, and triggers only. MySQL cursor is reachable from model 5 or greater. If you are looking MySQL Interview Questons then you can visit here. This will help you to crack your interviews.
MySQL cursor is read-only, non-scroll able and sensitive.
Non-scrollable
you can only fetch rows in the order decided with the aid of the SELECT statement. You can't fetch rows in the reversed order. In addition, you can't omit rows or soar to a precise row in the end result set.
Read-only
you can't replace statistics in the underlying desk thru the cursor.
A sensitive
there are two sorts of cursors: a touchy cursor and an insensitive cursor. Insensitive cursor factors to the genuine data, whereas an insensitive cursor makes use of transient replica of the data. An insensitive cursor performs quicker than an insensitive cursor due to the fact it does no longer have to make a brief reproduction of data. However, any exchange that made to the facts from different connections will have an effect on the records that is being used through an a touchy cursor, therefore, it is safer if you do now not replace the records that is being used by using an sensitive cursor. MySQL cursor is a sensitive.
Advantages of the use of Cursor
- Cursors can furnish the fest few rows earlier than the total result set is assembled. Without the use of cursors, the complete end result set need to be delivered earlier than any rows are displayed with the aid of the application. So the usage of cursor, higher response time is achieved.
- Using Cursor we can function row by way of row processing so we can function row smart validation or operations on every row.
- Cursors can be quicker than a whilst loop however at the fee of greater overhead.
- If we make updates to our except the usage of cursors in your software then we ought to ship separate SQL statements to the database server to practice the changes. This can move the opportunity of concurrency troubles if the end result set has modified on the grounds that it was once queried via the client. In turn, this raises the opportunity of misplaced updates. So the usage of cursor, higher concurrency Control can be achieved.
Disadvantages of the use of Cursor
- Each time when a row is fetched from the cursor it might also end result in a community spherical trip. This makes use of lots greater community bandwidth than the execution of a single SQL declaration like SELECT or DELETE and so on that makes solely one spherical trip.
- Cursor in SQL is transient work place created in the device memory, accordingly it occupies memory from your machine that may also be handy for different processes. So occupies extra sources and transient storage.
- Repeated community spherical journeys can degrade the pace of the operation the usage of the cursor.
Visit-: Remittance Sol
Top comments (0)