Skip to content

Instantly share code, notes, and snippets.

@niisar
Created April 24, 2016 16:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niisar/96cb7327c01640549350cf2f630d788c to your computer and use it in GitHub Desktop.
Save niisar/96cb7327c01640549350cf2f630d788c to your computer and use it in GitHub Desktop.
Delete FILESTREAM data
-- Delete row #1
DELETE FROM PhotoAlbum WHERE PhotoId = 1
SELECT * FROM PhotoAlbum
-- Forcing garbage collection won't delete the file without a BACKUP if using FULL recovery model
EXEC sp_filestream_force_garbage_collection
-- Switch from FULL to SIMPLE recovery model
SELECT name, recovery_model_desc FROM sys.databases WHERE name = 'PhotoLibrary'
ALTER DATABASE PhotoLibrary SET RECOVERY SIMPLE
SELECT name, recovery_model_desc FROM sys.databases WHERE name = 'PhotoLibrary'
-- Forcing garbage collection will now delete the file immediately
EXEC sp_filestream_force_garbage_collection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment