At SQLBits I had a number of conversations with a number of people over TSQL Smells, my open source project for static code analysis of SQL Code. The general opinion was that although the concept was sound, the process of getting it running ( and developing it further ) was not documented. Im sure that if you have sufficient .Net skills you could muddle through on your own, but since it will be mainly TSQL devs who have the interest here, I thought I would take the time to draw up some ‘Arse and Elbow’ documentation to get you started.
So lets go :
- Grab Visual Studio 2013. Community edition is fine operationally ( Im not a lawyer, check the licensing terms).
- After that has installed, update SSDT. Tools -> Extensions and Updates -> Updates -> Product Updates
- Install both the 32Bit and 64Bit versions of the DACFX framework, at time of writing latest is downloadable from http://www.microsoft.com/en-us/download/confirmation.aspx?id=45886
-
Ensure that the SSDT extensions directory ( C:Program Files (x86)Microsoft Visual Studio 12.0Common7IDEExtensionsMicrosoftSQLDBDAC120Extensions ) is read writable ( I use Everyone / Full control ).
That should be the tooling side of the equation sorted.
Now clone ( I wont go into what this means , a number of tutorials are available on github) the TSQL Smells repo on github http://github.com/davebally/TSQL-Smells
In terms of software this should now all be done.
Run up visual studio, load in the TSQLSmells solutions and “Rebuild Solution”.
If that all goes according to plan, you will now be able to run the unit tests
Image may be NSFW.
Clik here to view.
And if you are even more lucky they will all pass.
This now means that the rules are installed correctly and we can proceed onwards.
The unit test cases reference sql files that are held in the TSQLSmellsTest project, you can further test by loading this project and selecting the “Run Code Analysis” option.
You are now in a position to load your own projects and run the code analysis against them.
Finally, included in the solution is RunSCAAnalysis, this generates a small exe that can run the static code analysis rules against a database or dacpac.
Command line options for that are –S Server –o outputfile and one of –d
database or –f filename, it would be my intention with this that it that it would form part of your automated build/deploy framework (if you are not using SSDT) and break the build on a “Smell”.
I hope that this blog entry goes someway to starting you on your way to better TSQL Code quality and for my part, I will be giving it some love in the near future.