Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSMS not showing or scripting FILESTREAM attribute

I've created a table with a column that has the FILESTREAM attribute applied, like this:

CREATE TABLE dbo.FileStorage
(
    [ID] [uniqueidentifier] ROWGUIDCOL NOT NULL UNIQUE,
    [Filename] [nvarchar](255) NOT NULL,
    [Data] [varbinary](max) FILESTREAM NULL
)
GO

In a stored procedure, I'm referencing the PathName() function that should be available for the Data column above:

CREATE PROCEDURE GetPathName
    -- Add the parameters for the stored procedure here
    @fileId uniqueidentifier,
    @filePath nvarchar(max) output
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    SELECT @filePath = Data.PathName()
    FROM dbo.FileStorage
    WHERE ID = @fileId      
END
GO

However, when I execute the above script to create the stored procedure, SSMS prints an error: "Function PathName is only valid on columns with the FILESTREAM attribute.". I certainly created the table with the FILESTREAM attribute turned on (and filestream support is enabled in the DB), and I've even added a file to the table.

When I tried to verify that the column is indeed a FILESTREAM column, SQL Server Management Studio didn't cooperate. The attribute doesn't appear in the column properties pane, and when I scripted the table out, the FILESTREAM attribute doesn't appear.

Update: another oddity is that my FileStorage table doesn't ever appear in the list of tables presented by SSMS intellisense.

What's the deal? How can I manipulate or verify the FILESTREAM attribute in SSMS?

like image 236
Ben Collins Avatar asked Jul 19 '11 15:07

Ben Collins


People also ask

How to use FILESTREAM SQL?

To use FILESTREAM, you must create or modify a database to contain a special type of filegroup. Then, create or modify a table so that it contains a varbinary(max) column with the FILESTREAM attribute. After you complete these tasks, you can use Transact-SQL and Win32 to manage the FILESTREAM data.

How do I add Filestream attribute to an existing column?

1 Answer. Show activity on this post. If you encounter an error message "A table that has FILESTREAM columns must have a nonnull unique column with the ROWGUIDCOL property." you can add this property to a column with the following T-SQL statement: ALTER TABLE <TableName> ALTER COLUMN <IdColumnName> ADD ROWGUIDCOL .

How do I enable autocomplete in SSMS?

How to Enable IntelliSense Feature in SSMS. Open SSMS, click Tools -> Options -> Expand Text Editor -> Expand Transact-SQL and click on IntelliSense as shown in the snippet below. Under Transact-SQL IntelliSense Settings ensure “Enable IntelliSense” checkbox is enabled.

Does SQL Express Support Filestream?

SQL Server Express supports FILESTREAM. The 10-GB database size limit does not include the FILESTREAM data container.


1 Answers

If you have used SSMS Table Designer to modify your table, the FILESTREAM attribute of your column will be lost. In that case, you need to recreate the column and copy the existing data to it. here's a sample:

/* rename the varbinary(max) column
eg. FileData to xxFileData */
sp_RENAME '<TableName>.<ColumnName>', 'xx<ColumnName>' , 'COLUMN'
GO

/* create a new varbinary(max) FILESTREAM column */
ALTER TABLE <TableName>
ADD <ColumnName> varbinary(max) FILESTREAM NULL
GO

/* move the contents of varbinary(max) column to varbinary(max) FILESTREAM column */
UPDATE <TableName>
SET <ColumnName> = xx<ColumnName>
GO

/* drop the xx<ColumnName> column */
ALTER TABLE <TableName>
DROP COLUMN xx<ColumnName>
GO
like image 174
Karlo Medallo Avatar answered Jan 04 '23 05:01

Karlo Medallo