.netazure-sql-database

C# DB project with SqlAzureV12DatabaseSchemaProvider: add filegroup is not possible?


This is configuration section in my .sqlproj file:

<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<Name>MyDatabase</Name>
<SchemaVersion>2.0</SchemaVersion>
<ProjectVersion>4.1</ProjectVersion>
<ProjectGuid>{2bf9242c-9dd1-483d-b29b-10234a3f77d7}</ProjectGuid>
<DSP>Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider</DSP>
<OutputType>Database</OutputType>
<RootPath>
</RootPath>
<RootNamespace>MyDatabase</RootNamespace>
<AssemblyName>MyDatabase</AssemblyName>
<ModelCollation>1033, CI</ModelCollation>
<DefaultFileStructure>BySchemaAndSchemaType</DefaultFileStructure>
<DeployToDatabase>True</DeployToDatabase>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetLanguage>CS</TargetLanguage>
<AppDesignerFolder>Properties</AppDesignerFolder>
<SqlServerVerification>False</SqlServerVerification>
<IncludeCompositeObjects>True</IncludeCompositeObjects>
<TargetDatabaseSet>True</TargetDatabaseSet>
<DefaultSchema>dbo</DefaultSchema>
<IncludeSchemaNameInFileName>True</IncludeSchemaNameInFileName>

I want to use filegroups in my application. I add the file indx.sql with the following content:

GO
ALTER DATABASE [$(DatabaseName)]
    ADD FILEGROUP [INDX]

Now when I build the project in Visual Studio I get the following error:

Error SQL70015: Keyword or statement option 'ADD FILEGROUP' is not supported for the targeted platform.

According to this document, I assume that it could be possible with an Azure instance: https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-database-transact-sql-file-and-filegroup-options?view=azuresqldb-mi-current&preserve-view=true#azure-sql-managed-instance

Or I missed something?


Solution

  • Unfortunately, you don't have control over filegroups on Azure SQL Database. You cannot add or create new filegroups because Microsoft Azure platform will add the filegroups for you automatically if needed when databases increase their storage space. On Azure SQL Database filegroups are fully managed by Azure platform.

    However, on Azure SQL Managed Instance you can create filegroups same as on-premises SQL Server instances as explained here.