Does the Use of FILESTREAM Increase Both File System and Database Size?

23 Views Asked by At

Should the size of the database increase when adding a file using FILESTREAM? In practice, we are saving the binary data of the file in the database, causing the database size to increase by the size of the file. But then, what is the logic behind FILESTREAM? Isn't it supposed to manage files in the file system? Does this mean that both the size of the directory in the file system and the size of the database increase in such a scenario?

create database DEMOFS
    containment = none
    on primary 
    (name = 'datafile', filename = 'c:\fs\datafile.mdf')
    log on
    (name = 'demofc_log', filename = 'c:\fs\demofs_log.ldg')
go
alter database demofs
    add filegroup [fs] contains filestream
go

alter database demofs
    add file (name = fs1, filename = 'c:\filestream')
    to filegroup fs

use DEMOFS
go

create table demotab
(
col01 uniqueidentifier rowguidcol not null unique,
col02 nvarchar(100),
col03 varbinary(max) FILESTREAM,
col04 nvarchar(max),
col05 nvarchar(max)
)

Then, I add a file using OPENROWSET and write binary data to the database, causing my database to increase in size by the size of the file.

select 
    NEWID(),
    'Demo',
    import.BulkColumn,
    'TEST',
    '.pdf'

    from openrowset(bulk 'filepath\file.pdf', single_blob) as import
0

There are 0 best solutions below