【问题标题】:Add filestream to an existing table column将文件流添加到现有表列
【发布时间】:2016-07-11 02:32:54
【问题描述】:

我有下表列:

[Content] [varbinary](max) NULL

我想让它成为一个文件流列,所以我尝试了:

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.

如何将文件流添加到现有列?

【问题讨论】:

  • 我怀疑您可能需要创建另一列“alter table dbo.Files add Content_new varbinary(max) filestream not null”,然后将原始列中的内容复制过来。

标签: sql-server tsql sql-server-2014


【解决方案1】:

您需要执行以下操作(来自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

【讨论】:

  • 如果您遇到错误消息“具有 FILESTREAM 列的表必须具有具有 ROWGUIDCOL 属性的非空唯一列。”您可以使用以下 T-SQL 语句将此属性添加到列中:ALTER TABLE &lt;TableName&gt; ALTER COLUMN &lt;IdColumnName&gt; ADD ROWGUIDCOL。请注意,列 必须是 uniqueidentifier 类型。
猜你喜欢
  • 1970-01-01
  • 2016-11-13
  • 1970-01-01
  • 1970-01-01
  • 2016-07-04
  • 2017-04-29
  • 2020-12-19
  • 2018-02-21
相关资源
最近更新 更多