The topic describes the DF058 T-SQL code analysis rule.
EXECUTION RULES
Cursor is not declared as read-only.
It is recommended to declare a cursor with the READ_ONLY property if there are no plans to perform UPDATE or DELETE operations at the cursor position.
Cursors declared with READ_ONLY are optimized for read-only operations. This optimization can lead to improved performance compared to cursors without the READ_ONLY property, especially when dealing with large result sets.
Additionally, declaring a cursor as READ_ONLY prevents accidental modifications to the underlying data set. Without the READ_ONLY property, developers may inadvertently attempt to perform UPDATE or DELETE operations, potentially leading to unintended changes or data corruption.
DECLARE cur CURSOR LOCAL FORWARD_ONLY STATIC FOR SELECT
FirstName
,LastName
FROM dbo.Employee
DECLARE cur CURSOR LOCAL FORWARD_ONLY STATIC READ_ONLY FOR SELECT
FirstName
,LastName
FROM dbo.Employee