SQL Server FileStream

Source: Internet
Author: User
Tags filegroup

Sqlserer when installing, remember to check FileStream;

Start below:

Perform:

EXEC sp_configure filestream_access_level,2
RECONFIGURE

To restart the database service:

To create a database:

CREATE DATABASE [Filestream]

Because FileStream is a special-purpose filegroup, to create a filegroup specify Constains FileStream

ALTER DATABASE Filestream
ADD FILEGROUP fg_ft CONTAINS Filestream

When adding a filegroup, the physical file path does not need to be manually created, the manual creation will be error, I have encountered;

ALTER DATABASE [Filestream]
ADD FILE
(
Name=n ' Filestream1 ',
Filename=n ' F:\Filestream '
) to FILEGROUP fg_ft

Result: (Automatically created)

FILESTREAM.HDR is a FileStream system file, and Filesream container contains FileStream header information; do not delete

Create a containing varbinary (max) field and specify the FileStream property, and also the uniqueidentifier type and specify the ROWGUIDCOL property;

CREATE TABLE Filestre
(
ID uniqueidentifier ROWGUIDCOL not NULL UNIQUE,
NAME SYSNAME,
BLOB VARBINARY (MAX) FILESTREAM NULL
)

Insert data The first article is a text document, the second is a picture;

INSERT INTO Filestre
SELECT NEWID (), ' name1 ', * FROM OPENROWSET (BULK N ' F:\COUNTERS. TXT ', Single_blob) as FILE1
INSERT INTO Filestre
SELECT NEWID (), ' name2 ', * FROM OPENROWSET (BULK N ' F:\20160927.png ', Single_blob) as FILE1

The physical file path is automatically created, we insert two files, this file we can modify the file format, and can open look;

Below we test restore backup, very strange, also just solve my doubts above, I took the file group file path deleted, restore the file path can be created;

Backup:

BACKUP DATABASE [Filestream] to Disk=n ' F:\FILE_D.BAK '

BACKUP LOG [Filestream] to Disk=n ' F:\FILE_L.BAK '

Delete the database FileStream, delete the file path, the data files are not;

Restore the database below:

RESTORE DATABASE [Filestream] from disk=n ' F:\FILE_D.BAK ' with NORECOVERY
RESTORE LOG [Filestream] from disk=n ' F:\FILE_L.BAK '

All data is identical to the database before deletion;

SQL Server FileStream

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.