Question

Scenario: I have 3 environments that I am using, Dev, UAT and Live. Each of which having it's own database, MyDb_Dev, MyDb_UAT, MyDb_Live. Then I have a VS2012 Database project in my solution that contains all my scripts. This works nicely when I make changes to my model database (MyDb_Model) that is located locally.

What I want to do: I want to use the FileTables in SQL 2012 (which I understand how to set up), however I don't know how to script them to be able to configure the options to handle my environments. When I generate the scripts, it will hard code the name to be MyDb_Model as the FileGroup. Also, that said, when I do try and publish to my Dev database, it's complaining about the database options not being able to take the new scripts. When I script include the options of the Model database, it'll complain when I try to publish to my Dev database because of duplicating names.

Question: Can you script FileTables (with the database options) using the database project in V2012 to be configurable or do I need to manually make my own scripts?

Prefered: Compare MyDb_Model to Database project. Publish to MyDb_Dev as a newly created database.

Was it helpful?

Solution

Sounds like you'll want project variables to handle this where the variable contains the environment-specific text for each. You'd then use that variable in your objects instead of the hard-coded paths. The following would create a FileTable called "DocumentStore" and use the value for a variable called "FileTableDirectoryVariable" that you set up in your Project Properties - SQLCMD Variables. Set each of those in your Publish Profiles to use the correct directory, and you should be good. If you're using different filegroups for these tables, you should be able to tweak the FileGroup setting in a similar manner using a SQLCMD Variable.

CREATE TABLE DocumentStore AS FileTable
    WITH ( 
          FileTable_Directory = '$(FileTableDirectoryVariable)',
          FileTable_Collate_Filename = database_default
         );
GO
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top