Validating and Formatting T-SQL Code

Using the Validate SQL and Reformat SQL commands you can validate the syntax of your SQL code
and reformat it using the layout rules stored in the active layout template.

This topic contains the following sections:

Reformatting a selection of T-SQL code

reformat-1

1. Select Layout Template from the Quick Template List drop-down or edit the active Layout template using
the Options command of the SQL Enlight menu.

2. Select SQL code to reformat or else the whole document will be reformatted.

3. On the SQL Enlight menu click Reformat SQL
button or use the Ctrl + Alt + F keyboard shortcut.

reformat-2
Reformatting a T-SQL Script file

1. In SQL Server Management Studio or Visual Studio , on the File menu, click Open -> File.

2. Select file containing T-SQL script.

3. Choose Layout Template from the Quick Template List drop-down or use currently selected.

4. Use Reformat SQL button on the SQL Enlight Toolbar
or Reformat SQL menu item on the SQL Enlight
menu.

You can undo the changes to the script using the standard SQL Server Management Studio and Visual Studio Undo
command.

Validating T-SQL Script

1. Select T-SQL script in the text editor.

2. Use Validate SQL command on the SQL Enlight menu.

If there are T-SQL script analysis rules violations, the SQL Enlight Error List Window will be displayed and the errors will be marked in the text editor.

reformat-3

Double-click any error message entry to open the file where the problem occurs, and move to the error location.

To sort the list, click any column header.

Use the Errors, Warnings, and Messages buttons to select which entries to display.

Errors

Indicates the number of Errors in the list. Click to toggle whether Errors are displayed.

Warnings

Indicates the number of Warnings in the list. Click to toggle whether Warnings are displayed.

Messages

Indicates the number of Messages in the list. Click to toggle whether Messages are displayed.

See Also