Search code examples
sql-servervisual-studiosql-server-data-toolsdacpac

SQL Server Data Tools (SSDT) - Decide data type at deploy time?


does anyone know of a technique to decide the data type of a column at deploy time with SSDT / dacpac deployment, depending on what features are available on the target SQL Server instance? Concrete example:

CREATE TABLE [HasBlob] (
    [Id] INT PRIMARY KEY,
    [Guid] [uniqueidentifier] ROWGUIDCOL NOT NULL UNIQUE,
    [Data] VARBINARY(MAX) FILESTREAM NULL
)

In this case, I would like to be able to automatically fall back to a conventional VARBINARY(MAX) blob instead of a FILESTREAM if FILESTREAM is not enabled for the SQL Server instance.


Solution

  • One way would be to query the current database's filegroups via sys.data_spaces, for example:

    IF EXISTS(SELECT * FROM sys.data_spaces WHERE type = 'FD')
    BEGIN
    -- use create statement with FILESTREAM
    END;