Unused variable detection in SQL Server

霸气de小男生 提交于 2020-01-24 20:12:34

问题


Is there a way to identify local variables that have been created (or even created and set to a value), but are never used again? I'm thinking along the lines of when an IDE will underline such variables with a squiggly line.

If this isn't something that can be enabled within SSMS, are there any add-ins that do this?

(Particularly interested in SQL Server 2008 R2, if it matters)

Thanks for the insight.


回答1:


ApexSQL Refactor, a free SSMS and VS SQL formatting and refactoring add-in, has a feature that finds unused variables and parameters and cleans up your code by identifying and removing parameters and variables that aren’t used.

You can find more info about this feature in this article

Disclaimer: I work for ApexSQL as a Support Engineer




回答2:


SSMS doesn't do that, unfortunately. At all. Which surprises me in a way, because it can't be that hard to determine.

I don't know about add-ins, but Mr. Smith had a suggestion in his comment.




回答3:


you can try SqlCodeGuard from http://www.sqlcodeguard.com/ - free addin for SSMS

it has a bunch of t-sql code checks and have rule "MI005 Variable is declared but never used"



来源:https://stackoverflow.com/questions/17624319/unused-variable-detection-in-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!