SQL Server Error 1063: Filegroup ALTER Fix
In this article
SQL Server error 1063 means you tried to add a filegroup with ALTER DATABASE ... ADD FILEGROUP, but that statement is not valid for adding a filegroup. The correct command is ALTER DATABASE ... ADD FILEGROUP only when the database is in a state that permits it, and the usual cause is that you are using ALTER DATABASE ... ADD FILE syntax incorrectly, or you are trying to add a filegroup to a database that is read-only, offline, or in a state where filegroup changes are blocked. The fix is to use the correct ALTER DATABASE statement, ensure the database is online and writable, and verify you have the required permissions. This guide walks through the exact steps to resolve error 1063 and add a filegroup successfully.
What You'll Need
- SQL Server Management Studio (SSMS) or another client such as Azure Data Studio, connected to the instance.
- Membership in the
db_ownerfixed database role orsysadminserver role, or ALTER permission on the database. - The database must be online and not read-only.
- The name you want for the new filegroup, and optionally the logical file names and physical paths for data files you plan to add to it.
Step-by-Step
Confirm the database is online and writable. Run the following query in a new query window:
SELECT name, state_desc, is_read_only FROM sys.databases WHERE name = 'YourDatabaseName';If
state_descis notONLINE, bring the database online first. Ifis_read_onlyis 1, you must make it writable withALTER DATABASE YourDatabaseName SET READ_WRITE;before adding a filegroup. Note that menu labels and query wording can differ slightly by SQL Server version and client tool, but the system views and commands above are standard.Check that you are using the correct syntax. Error 1063 is raised when the parser sees
ADD FILEGROUPin a context where it is not allowed, or when you accidentally combine it withADD FILE. The valid form is:ALTER DATABASE YourDatabaseName ADD FILEGROUP NewFilegroupName;Do not include a filename or path in the
ADD FILEGROUPclause. Files are added separately withALTER DATABASE ... ADD FILE ... TO FILEGROUP ....Verify the filegroup does not already exist. Query the catalog:
SELECT name FROM sys.filegroups WHERE name = 'NewFilegroupName';If a row is returned, choose a different name or drop the existing filegroup first (only if it is empty and not the primary filegroup).
Run the corrected statement. In SSMS, open a new query window against the target database (or use
USE YourDatabaseName;first), paste the correctedALTER DATABASEstatement, and execute it. A successful run returns no error and the filegroup appears in Object Explorer under the database's Storage > Filegroups node.Add data files to the new filegroup if needed. Use a separate statement:
ALTER DATABASE YourDatabaseName ADD FILE (NAME = N'NewDataFile', FILENAME = N'C:\SQLData\NewDataFile.ndf', SIZE = 5MB, FILEGROWTH = 5MB) TO FILEGROUP NewFilegroupName;Adjust the path to a location the SQL Server service account can access. The
.ndfextension is conventional for secondary data files but not required.Confirm the result. Re-run the
sys.filegroupsquery and also checksys.database_filesto see the new file assigned to the correct filegroup. Optionally set the new filegroup as default withALTER DATABASE ... MODIFY FILEGROUP NewFilegroupName DEFAULT;if that is your intent.
Common Mistakes
- Mixing ADD FILEGROUP with ADD FILE. The two clauses are separate statements. Putting a filename inside
ADD FILEGROUPtriggers error 1063. - Running against a read-only or restoring database. Filegroup changes are blocked while the database is read-only, offline, or in the middle of a restore. Check
sys.databasesfirst. - Using the wrong database context. If you omit
USEand the database name in the statement, you may targetmasteror another database where the operation is not intended. - Forgetting permissions. A login without ALTER on the database gets a permission error, not 1063, but users often misread the two. Confirm role membership before troubleshooting syntax.
- Reusing an existing filegroup name. SQL Server will not create a duplicate; the statement fails and the error can be confused with 1063 if you are editing an old script.
Tips
- Keep filegroup and file creation in separate statements so a syntax error in one does not roll back the other.
- Use
N'...'Unicode literals for names and paths to avoid collation surprises. - Place new data files on a drive with enough free space and, for performance, on a separate volume from the log files.
- Script the change and test it on a development copy first; filegroup changes are metadata operations but adding files consumes disk immediately.
- Remember that the primary filegroup cannot be dropped, and a filegroup containing data cannot be dropped until its files are emptied or removed.
Troubleshooting
If the corrected statement still fails, work through these checks in order:
- Re-read the exact error message. Error 1063 is specifically about the
ADD FILEGROUPclause. If the message mentions a different object, you are looking at a different problem. - Check database state again. A database can move to
RECOVERY_PENDINGorSUSPECTafter a restart. Resolve that state before retrying. - Confirm permissions. Run
SELECT IS_ROLEMEMBER('db_owner');in the target database. A 0 means you need elevated rights. - Look for a transaction or lock. Another session holding a schema modification lock can block the ALTER. Query
sys.dm_tran_locksor check Activity Monitor for blocking sessions. - Try a minimal statement. Execute only
ALTER DATABASE YourDatabaseName ADD FILEGROUP TestFG;with no extra clauses. If that succeeds, the problem was in the additional syntax. - Review the SQL Server error log for accompanying messages about the database or permissions that the client did not display.
If none of these resolve it, capture the full statement and error text and consult the official SQL Server documentation for ALTER DATABASE file and filegroup options for your version.
Frequently Asked Questions
What exactly causes SQL Server error 1063?
It is raised when the ADD FILEGROUP clause is used incorrectly, most often by combining it with file definition syntax or running it against a database that cannot accept the change.
Can I add a filegroup to a read-only database?
No. Set the database to read-write first with ALTER DATABASE ... SET READ_WRITE, then add the filegroup.
Do I need to stop the database to add a filegroup?
No. Adding a filegroup is an online metadata operation and does not require downtime, though it may briefly block other schema changes.
How do I check which filegroups exist?
Query SELECT name FROM sys.filegroups; in the target database, or expand Storage > Filegroups in Object Explorer.
Can I add a file to a filegroup in the same statement?
No. Add the filegroup first, then use a separate ALTER DATABASE ... ADD FILE ... TO FILEGROUP statement.
Why does my script work on one server but not another?
Likely differences are database state, permissions, or the presence of a filegroup with the same name. Compare sys.databases and sys.filegroups on both servers.