Unused variable detection in SQL Server

2019-07-29 22:30发布

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.

3条回答
Melony?
2楼-- · 2019-07-29 22:59

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.

查看更多
Root(大扎)
3楼-- · 2019-07-29 23:02

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

查看更多
仙女界的扛把子
4楼-- · 2019-07-29 23:16

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"

查看更多
登录 后发表回答