I have a SQL Server database project (VS2017) and in project properties, the SQLCMD Variables tab looks like this:
Question: I can create a SQLCMD variable and set a Default Value and a Local Value for it. What is the difference?
Note: I do currently use SQLCMD variables in my project, so I think I know how they work, but I can't get my head round this distinction. According to what documentation I can find (highlighting is mine):
In SQL Server Database Projects you can utilize SQLCMD variables to provide dynamic substitution to be used for debugging or publishing. You enter the variable name and values and during build, the values will be substituted. If there are no local values, the default value will be used. By entering these variables in project properties, they will automatically be offered in publishing and are stored in publishing profiles. You can pull in the project values of the variables into publish via the Load Values button.
So it seems that:
How does this help me? There seems to be no point in having both values set, so why do we need two different values?
Variables that are used in scripts are called scripting variables. Scripting variables enable one script to be used in multiple scenarios. For example, if you want to run one script against multiple servers, instead of modifying the script for each server, you can use a scripting variable for the server name.
The sqlcmd Utility lets you enter Transact-SQL statements, system procedures, and script files at the command prompt, in SQLCMD mode in SQL Server Management Studio, and in a Windows script file or in an operating system (Cmd.exe) job step of a SQL Server Agent job.
Database development project created by Visual Studio, a Windows software development IDE; stores the schema of the database and can include SQL source code; used for creating databases for SQL Server, Microsoft's relational database management system (RDBMS) software. Older .
Local has higher precedence over default when Publishing.
This means that if you have both default and local values filled in, and click Publish, your variable values in Publish window will be automatically filled by local values, even without you clicking on the Load Values button.
If you only have default values, then no values will be automatically filled in the Publish window, until you click on the Load Values button.
Then values will get filled in with the default values.
You can always override the variable values in the Publish window, even the ones which were filled in as local.
So, purpose of local values is to prepare the filled in, final values when Publishing.
Leaving them empty demands for you to either click on Load Values to get the default values, or to manually fill the variable values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With