SA0223 : The MODIFY FILEGROUP READONLY and READWRITE syntax is deprecated
Introduction
Section titled “Introduction”Using deprecated keywords for database filegroup modifications can lead to compatibility issues and potential failures in future versions of SQL Server.
Description
Section titled “Description”In SQL Server, managing database filegroups is a common task that includes setting filegroups to either READONLY or READWRITE . However, the ALTER DATABASE MODIFY FILEGROUP command with these keywords is deprecated and will be removed in future versions of SQL Server.
For example:
-- Deprecated usage of altering database filegroupALTER DATABASE MyDatabase MODIFY FILEGROUP MyFileGroup READONLY;Using these keywords is problematic because:
-
Future-proofing your application becomes difficult, as continued use of these commands can lead to breaking changes when upgrading SQL Server versions.
-
It may indicate legacy or outdated code practices that could potentially lead to compatibility issues.
How to fix
Section titled “How to fix”Modify your T-SQL code to avoid using deprecated keywords like READONLY and READWRITE when altering database filegroups.
Follow these steps to address the issue:
1.Open your T-SQL script or query in SQL Server Management Studio (SSMS).
2.Locate any instance of the ALTER DATABASE MODIFY FILEGROUP command that uses the READONLY or READWRITE keywords.
3.Replace the deprecated syntax with the updated command: MODIFY FILEGROUP READ_ONLY or READ_WRITE as appropriate.
4.Execute the modified query to apply the changes to your database.
For example:
-- Corrected usage of altering database filegroupALTER DATABASE MyDatabase MODIFY FILEGROUP MyFileGroup READ_ONLY;The rule has a Batch scope and is applied only on the SQL script.
Parameters
Section titled “Parameters”Rule has no parameters.
Remarks
Section titled “Remarks”The rule does not need Analysis Context or SQL Connection.
Effort To Fix
Section titled “Effort To Fix”20 minutes per issue.
Categories
Section titled “Categories”Deprecated Features, Bugs
Additional Information
Section titled “Additional Information”Deprecated Database Engine Features in SQL Server 2017
Example Test SQL
Section titled “Example Test SQL”ALTER DATABASE TestDb1 MODIFY FILEGROUP Fg1 READONLY;
ALTER DATABASE TestDb1 MODIFY FILEGROUP Fg2 READWRITEAnalysis Results
Section titled “Analysis Results”| Message | Line | Column | |
|---|---|---|---|
| 1 | SA0223 : The MODIFY FILEGROUP READONLY and READWRITE syntax is deprecated. | 1 | 45 |
| 2 | SA0223 : The MODIFY FILEGROUP READONLY and READWRITE syntax is deprecated. | 3 | 45 |