Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 1064: Filegroup Cannot Be Used With Log

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

SQL Server error 1064 ("A filegroup cannot be used with log") appears when you try to create or alter a database and specify a filegroup for a log file, or when you attempt to add a log file to a filegroup that is meant only for data files. The fix is to remove the filegroup clause from the log file definition and let SQL Server place the log in its own logical space. You do not need to assign a filegroup to transaction log files at all.

What You'll Need

  • SQL Server Management Studio (SSMS) or another client such as Azure Data Studio, connected with an account that has permission to create or alter the database (dbcreator or sysadmin, or ALTER on the database).
  • The exact CREATE DATABASE or ALTER DATABASE statement that is failing, so you can edit it.
  • If you are using the SSMS graphical designer, the ability to switch to the script view or to edit the file properties directly.
  • Basic familiarity with the difference between data files (.mdf/.ndf) and log files (.ldf).

Step-by-Step

  1. Read the full error message. Error 1064 is usually accompanied by the statement that caused it. Note whether you are running CREATE DATABASE, ALTER DATABASE, or using the New Database dialog in SSMS. The message points to the log file entry that has a FILEGROUP clause attached.
  2. Open your script or the generated script. If you used the SSMS New Database dialog, click the Script button at the top of the dialog instead of OK, and review the generated T-SQL. Look for a line similar to LOG ON (NAME = N'MyDb_log', FILENAME = N'C:\...\MyDb_log.ldf', FILEGROUP = N'PRIMARY') or any other filegroup name after the log file definition.
  3. Remove the FILEGROUP clause from the log file entry. Transaction log files do not belong to filegroups. The LOG ON section should list only NAME, FILENAME, and optionally SIZE, MAXSIZE, and FILEGROWTH. Delete the FILEGROUP = ... portion entirely. Do not replace it with another filegroup name; the clause must be absent.
  4. Check the data file entries separately. Data files (the PRIMARY file and any secondary .ndf files) can and often should have a FILEGROUP clause. Only the log file entry must be free of it. Make sure you have not accidentally moved a data file into the LOG ON section or a log file into the ON section.
  5. Run the corrected statement. Execute the script again. If the database was partially created before the error, drop it first with DROP DATABASE IF EXISTS YourDbName; and then recreate it, or use ALTER DATABASE to add the log file correctly if the database already exists.
  6. If you are adding a log file to an existing database, use ALTER DATABASE YourDbName ADD LOG FILE (NAME = N'YourDb_log2', FILENAME = N'C:\...\YourDb_log2.ldf', SIZE = 64MB, FILEGROWTH = 64MB); with no FILEGROUP clause. Then run ALTER DATABASE YourDbName MODIFY FILEGROUP [YourFilegroup] DEFAULT; only if you need to change the default data filegroup, not for the log.
  7. Verify the result. Query sys.database_files and sys.filegroups to confirm the log file has no filegroup association. In SSMS, right-click the database, choose Properties, and check the Files page: the Filegroup column for the log file should be blank or show "(not applicable)".

Common Mistakes

  • Putting the log file in the PRIMARY filegroup because the script template already had FILEGROUP = N'PRIMARY' on every file line. The log line must be edited separately.
  • Confusing error 1064 with other SQL Server errors that share the number range. Error 1064 is specifically about filegroups and log files; if your message differs, check the actual text before applying this fix.
  • Leaving a trailing comma after removing FILEGROUP, which causes a syntax error near the closing parenthesis.
  • Adding a log file to a user-defined filegroup that was created for data only. Log files never join filegroups, even custom ones.
  • Assuming the SSMS graphical designer will prevent the mistake. Older templates or hand-edited scripts can still include the clause.

Tips

  • Keep log files on a separate physical drive from data files for performance, but do not try to express that separation through filegroups. Use the FILENAME path instead.
  • Use one log file per database. SQL Server writes to log files sequentially and multiple log files do not improve throughput.
  • When scripting a new database, start from a known-good template and remove any FILEGROUP clause from the LOG ON block before running it.
  • If you need to move a log file, use ALTER DATABASE ... MODIFY FILE with the new FILENAME, take the database offline, move the file at the OS level, and bring it back online. Filegroups are not involved.

Troubleshooting

If the error persists after removing FILEGROUP, check that you edited the correct statement: SSMS may have generated a batch with multiple statements, and the failing one may be later in the script. Run the script one statement at a time to isolate it. If you are using a third-party tool or an ORM migration that generates the SQL, inspect the generated script rather than the tool's UI, because the tool may be adding the clause automatically; update the tool's configuration or template. If the database already exists and you are altering it, confirm the log file name is not already in use and that the path is valid and writable by the SQL Server service account. If you see a permission error after fixing 1064, that is a separate issue: grant the service account access to the folder. If the database is in a partially created state, drop and recreate it, or restore from backup if it contained data. When in doubt, script the database from a working server and compare the LOG ON section line by line.

Frequently Asked Questions

Can a transaction log file belong to a filegroup?

No. Log files are managed separately from filegroups, which exist only to group data files for allocation and backup purposes. Any FILEGROUP clause on a log file causes error 1064.

Does this error mean my database is corrupted?

No. Error 1064 is a syntax and definition error in the statement you ran, not a corruption indicator. Fix the statement and rerun it.

Why did the SSMS New Database dialog produce this error?

The dialog itself does not normally add FILEGROUP to log files, but if you edited the generated script or used an older template, the clause can appear. Always review the script before executing it.

Can I put the log file in a user-defined filegroup to separate it from data?

No. Separation is achieved with file paths on different drives, not filegroups. Filegroups apply only to data files.

What if I need multiple log files?

SQL Server allows multiple log files, but they are written sequentially and do not improve performance. Each must be defined in LOG ON without a FILEGROUP clause.

Does error 1064 occur in Azure SQL Database?

Azure SQL Database manages files and filegroups for you, so you generally cannot issue these file-level statements there. The error is most common on SQL Server instances where you control file placement.