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 2: Getting Started with <strong>FILESTREAM</strong><strong>FILESTREAM</strong> and triggersJust like other columns, <strong>FILESTREAM</strong> columns are accessible from within DMLtriggers. <strong>The</strong> <strong>FILESTREAM</strong> columns can be accessed from a trigger in the same way asa regular VARBINARY(MAX) column. DML triggers get fired even when modifying the<strong>FILESTREAM</strong> data using Win32 I/O streaming.It is not good practice to print debug information from a trigger. However, for thepurpose <strong>of</strong> showing that the <strong>FILESTREAM</strong> columns are accessible from a trigger, we'llcreate an INSERT trigger that prints the size <strong>of</strong> the <strong>FILESTREAM</strong> data value beinginserted (Listing 2-22).CREATE TRIGGER TGR_Items ON dbo.ItemsAFTER INSERTASBEGINDECLARE @size INTSELECT @size = DATALENGTH(ItemImage)FROM INSERTEDPRINT '<strong>FILESTREAM</strong> Size :' + STR(@size)ENDListing 2-22:An INSERT trigger that prints the size <strong>of</strong> the <strong>FILESTREAM</strong> data value being inserted.Now we'll insert a new record into the <strong>FILESTREAM</strong> column <strong>of</strong> the Items table using thescript in Listing 2-23.-- Insert the data to the tableINSERT INTO Items( ItemID ,ItemNumber ,ItemDescription ,ItemImage)79

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

Saved successfully!

Ooh no, something went wrong!