One feature I really enjoy in SQL Server Data Tools (SSDT) for database development is the ability to include scripts in the project that are not used in the build process.  This is handy for storing data validation, or sample data creation scripts, for example.

The simplest way to add a script to a database project is to right click the folder where the script will be added, and select Add New\Script.  This brings up the dialog below.  By selecting the “Script (Not in build)” option, the script is added to the project, and will not be included in the build process.  Simple!

SSDTNoBuild_01
Adding a Script to SSDT Database Project

While working on a project recently, I had written a handful of scripts outside SSDT, and wanted to add them to the SSDT project.  This time I selected Add\Existing Item, and selected the script I had just written.  I rebuilt my project, but saw the following error message.

SQL 70001: This statement is not recognized in this context.

SSDTNoBuild_02
SSDT Database Project Build Error

With other scripts, I’ve seen the following error.

SQL 71006: Only one statement is allowed per batch. A batch separator, such as ‘GO’, might be required between statements.

The SQL in my script was valid.  I could execute it in SQL Server Management Studio.  It took me a while to figure out what was going on.  But then I realized the build was failing on a script I did not want included in the build process.  AHA!

When I added the script to the project, the default of the Build Action property was “Build”.  This , of course, means the script will be included in the build process.  I needed to change this property to “None”.

SSDTNoBuild_03
Script File Build Action Property

After this simple Build Action property change, the project build completed successfully.

This is not a ground breaking discovery, but a simple tip I felt was worth sharing.

A special “Hello” to those of you who found this post by searching for “This statement is not recognized in this context” or “Only one statement is allowed per batch. A batch separator, such as ‘GO’, might be required between statements!”

Advertisements