17.07.2015 Views

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 7: <strong>FILESTREAM</strong> Database AdministrationUSE NorthPoleGOCREATE PARTITION FUNCTION NPPartFN (INT) ASRANGE RIGHT FOR VALUES (4)CREATE PARTITION SCHEME NPPartDBSch ASPARTITION NPPartFN TO([PRIMARY],[NorthPole2])GOCREATE PARTITION SCHEME NPPartFSSch ASPARTITION NPPartFN TO(NorthPole_fs1, NorthPole_fs2)GOListing 7-29:Creating a partition function and scheme.First, this code creates a partition function, NPPartFN, which will split data across tw<strong>of</strong>ilegroups; relational data will be split across the primary and secondary data files, and the<strong>FILESTREAM</strong> data will be divided across the two <strong>FILESTREAM</strong> filegroups.We will associate this function with the ItemID column <strong>of</strong> the Items table, such thatrows with ItemID less than 4 will go to the first filegroup (PRIMARY for relational dataand NorthPole_fs1 for <strong>FILESTREAM</strong> data), and those with 4 and above will go to thesecond filegroup (NorthPole2 for relational data and NorthPole_fs2 for <strong>FILESTREAM</strong>data). Of course, these numbers are very small and are used only for demonstrationpurposes. In the real world, you could use a larger value, or you might want to partitionbased on date, or some other value.<strong>The</strong> second part <strong>of</strong> the code creates two partition schemes; one for the relational data andthe other for the <strong>FILESTREAM</strong> data. Note that the partition switching <strong>of</strong> <strong>FILESTREAM</strong>data works only when the RIGHT operator is used in the partition function. It does notwork with LEFT, which is a confirmed bug in the current versions <strong>of</strong> <strong>SQL</strong> <strong>Server</strong>.<strong>The</strong> next step is to create the Items table, exploiting our new partition scheme, as shownin Listing 7-30.301

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!