2016-03-23 50 views
2

我有以下表列:添加FILESTREAM到現有的表列

[Content] [varbinary](max) NULL 

我想使它成爲一個FILESTREAM列,所以我嘗試:

alter table dbo.Files 
    alter column Content add filestream 

但我得到的錯誤:

Incorrect syntax near 'filestream'. 

我也試過

alter table dbo.Files 
    alter column Content varbinary(max) filestream not null 

但我得到的錯誤:

Cannot alter column 'Content' in table 'Files' to add or remove the FILESTREAM column attribute. 

我如何添加FILESTREAM現有列?

+0

我懷疑你可能需要創建另一列「改變表dbo.Files 添加Content_new VARBINARY(最大值)的文件流不爲空「然後複製原始欄中的內容。 –

回答

2

你需要做以下(從here來源):

/* 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