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>If the table already has a UNIQUEIDENTIFIER column with all the required characteristics,you can simply go ahead and add the <strong>FILESTREAM</strong> column using the ALTERTABLE script in Listing 2-9. However, if the table does not have a UNIQUEIDENTIFIERcolumn then you need to add one, with all the required attributes. Listing 2-11 shows howto do this.ALTER TABLE [dbo].[Items]ADD ItemID UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL UNIQUEGOListing 2-11:Adding a UNIQUEIDENTIFIER column with all the required attributes.A third possible outcome is that the table already has a UNIQUEIDENTIFIER column, butit does not have all the required attributes. For example, the column may allow NULLS,or it may not be marked as a ROWGUIDCOL, and so on. Depending upon your designrequirements, you could either add a new column with the required attributes, as shownin Listing 2-11, or you could change the existing column, as shown in Listing 2-12; note,though, that a table can have only one ROWGUIDCOL.-- Create a table with a UNIQUEIDENTIFIER ColumnCREATE TABLE [dbo].[Items]([ItemID] UNIQUEIDENTIFIER ,[ItemNumber] VARCHAR(20) ,[ItemDescription] VARCHAR(50))-- Alter the UNIQUEIDENTIFIER column to NOT NULLALTER TABLE ItemsALTER COLUMN ItemID UNIQUEIDENTIFIER NOT NULL-- Add a UNIQUE ConstraintALTER TABLE ItemsADD CONSTRAINT IX_ItemID UNIQUE(ItemID)-- Create a ROWGUIDCOLALTER TABLE ItemsALTER COLUMN ItemID ADD ROWGUIDCOL65

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

Saved successfully!

Ooh no, something went wrong!