Code Analysis for SQL Server command line
Published 30 May 2017
The code analysis command line, sqlcodeguard.exe, can target a specified database or folder or scripts. Note that while in preview the command line is not fully supported, although we are receptive to feedback. Please contact sales@red-gate.com for more information.
To run code analysis as part of an automated process, such as continuous integration, a SQL Change Automation license is required.
Release History
| Version | Release notes |
|---|---|
| 4_patch_4 | SCG-2019-10-17-11-40-22-46.zip includes SQL Server 2019 support |
| 4_patch_3 | Improvements to the html report. A fix to the severity regression. |
| 4_patch_2 | If .htm or .html is specified as the outfile, an html file will be generated instead of an xml file. Known issue: this version breaks the ERROR severity. |
| 4_patch |
|
| 4 |
|
| 3_patch |
|
Using SQL Code Guard with the command line
The command line utility, SqlCodeGuard.Cmd.exe, can analyze the existing database and folder with scripts files and supports the following parameters:
| Parameter:value | Alias | Description |
|---|---|---|
| /help | /h, /? | Output command line syntax help |
| /server:<server\instance> | /s | The server name to connect to |
| /database:<database> | /d | The database name to analyze |
| /user:<username> | /u | The user name. If no user is specified, Windows authentication will be used |
| /password:<password> | /p | The user password |
| /outfile:<file name> | /out | The file name to store the result (xml by default, but will generate html if file is specified as .htm or .html) |
| /source:<path> | The path to the file or folder with the SQL scripts to analyze | |
| /config:<settings file> | /c | The settings file to use (the UI saves its settings in %APPDATA%\SqlCodeGuard.Addin\settingsv3.xml) |
| /quiet | /q | This is silent mode for minimal messages |
| /log:<file name> | The log file name | |
| /include:<ALL | ISSUECODE1;ISSUECODE2{...}> | Can specify all or a semicolon-separated list of code issues to include (with severity "error" in v4, "warning" in v3) | |
| /exclude:<ALL | ISSUECODE1;ISSUECODE2{...}> | Can specify all or a semicolon-separated list of code issues to exclude (with severity "error" in v4, "warning" in v3) | |
| /warning:<ALL | ISSUECODE1;ISSUECODE2{...}> | Can specify all or a semicolon-separated list of code issues to be set to severity "warning" (switch available in v4 only) |
If /include, /exclude or /config are not used, all rules will apply by default.
The following example checks the AdventureWorks database on localhost with a specified instance name for all issues, and outputs the results as an .xml file:
SqlCodeGuard.cmd.exe /s:localhost\instancename /d:AdventureWorks /include:all /exclude:BP007;DEP004;ST001 /out:results.xml
Severities
| Severity | Description | Exit code |
|---|---|---|
| ignore | The rule will not be run and has no impact on the results | n/a |
| warning | The rule will be run, but is not intended to fail a build process | 0 |
| error | The rule will be run and will fail a build process | 1 |
Note: It is not yet possible to set the "error" severity in SQL Prompt. The settings file will need to be edited manually to achieve this.
Dependencies
The command line, SqlCodeGuard40.Cmd.exe, requires the following files to be present.
- Microsoft.SqlServer.TransactSql.ScriptDom.dll
- SqlCodeGuard40.Core.dll