Revision17
Revision17

Reputation: 73

Change run action in Visual Studio database project

I have a database project in Visual Studio 2008, and I want the ability to run a preprocessor on my sql code (using it to allow for variable database names without resorting to dynamic sql). So I'd like to change what action occurs when I hit the run button to include running the code through the preprocessor automatically.

Is there a way to do this? I looked through the dbp file, and there don't seem to be any options even close to this.

Upvotes: 2

Views: 307

Answers (1)

Jose Basilio
Jose Basilio

Reputation: 51498

One option is to use SQLCMD Mode in your database project scripts.
(VS Menu: Data -> TSQL Editor -> SQLCMD Mode).

In your scripts you can define variables that get replaced when you run them. Example:

:SETVAR tablevar Customers
GO
SELECT * FROM $(tablevar) /* translates to SELECT * FROM Customers */

Upvotes: 3

Related Questions