The topic describes the DF022 T-SQL code analysis rule.
BEST PRACTICE
The cursor name is reused.
A cursor with the same name has been declared earlier. Avoid reusing cursor names.
It’s important to avoid reusing cursor names to prevent potential conflicts and confusion in the code. Unique cursor names ensure clarity and maintainability, making it easier to understand and debug the code. Additionally, reusing cursor names can lead to unintended consequences or errors, especially in complex or multi-part scripts.
DECLARE cur CURSOR LOCAL FOR
SELECT CustomerID FROM dbo.Customer
OPEN cur
FETCH NEXT FROM cur INTO @CustomerId
DECLARE cur CURSOR LOCAL FOR
SELECT CountryID FROM dbo.Country
OPEN cur
FETCH NEXT FROM cur INTO @CoutryId
DECLARE cur CURSOR LOCAL FOR
SELECT CustomerID FROM dbo.Customer
OPEN cur
FETCH NEXT FROM cur INTO @CustomerId
DECLARE curCountry CURSOR LOCAL FOR
SELECT CountryID FROM dbo.Country
OPEN curCountry
FETCH NEXT FROM curCountry INTO @CoutryId