SQL Server Data Tools – Local SQLCMD Variables

Here is something that is not documented very well. In SQL Server Data Tools projects we have the ability to include SQLCMD variables. The idea is to allow access to a different set of resources at development time without getting compile time errors. In the example below I have variable called LinkedServer that points to a SQL Server Linked Server. In production it could be called something else.

We can see a Default value of DEV and a Local value MYDEV. So what is the difference between the two?

Firstly MYDEV will be used in preference to DEV however; it is not mandatory to include a Local value. The difference comes down to where the value is stored.

The Default value is stored in the project file within the project folder. <project>.sqlproj

This file will be checked into your source code repository and will be pulled down by every developer of the project. So every developer sees DEV as a default value.

The Local value is stored in the project user file within the project folder. <project>.sqlproj.user

This file must NOT be checked into your source code repository thus allowing each developer to have their own value.