I am looking into filegroup backups for a database. I want to have all the tables in the PRIMARY filegroup to be backed up and restored, while the tables in the SECONDARY filegroup are not. My queries work fine when the tables are just being edited, but when they are truncated, the table in the SECONDARY filegroup is restored.
When I do a "DELETE FROM" modification to the table in SECONDARY filegroup, it stays that way after restoring. But when I do a "TRUNCATE TABLE" on the same table, all the content comes back after the restore. I'm suspecting the table in the SECONDARY filegroup is still backed up by the PRIMARY one, but that doesn't make too much sense, as the delete line didn't get restored.
--- Create PRIMARY file group backup ---
Use master
BACKUP DATABASE database_name
FILEGROUP = 'PRIMARY'
TO DISK = 'some_location'
--- Restore PRIMARY file group ---
USE master
RESTORE DATABASE database_name
FILEGROUP = 'PRIMARY'
FROM DISK = 'some_location'
WITH PARTIAL, RECOVERY, REPLACE
--- Restore the other filegroup using a recovery-only database restore ---
USE master
RESTORE DATABASE database_name
FILEGROUP = 'SECONDARY'
WITH RECOVERY