我在现有SQL Server 2014数据库上有一个表,如下所示:
CREATE TABLE [dbo].[Files](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Content] [varbinary](max) NULL,
[Created] [datetime2](7) NOT NULL,
[Flag] [nvarchar](100) NULL,
[Key] [uniqueidentifier] NOT NULL,
[MimeType] [nvarchar](400) NOT NULL,
[Name] [nvarchar](400) NULL,
[Pack] [uniqueidentifier] NOT NULL,
[Slug] [nvarchar](400) NULL,
[Updated] [datetime2](7) NOT NULL,
CONSTRAINT [PK_File] PRIMARY KEY CLUSTERED
(
[Id] ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
什么是TEXTIMAGE_ON,为什么不只是[PRIMARY]?
如何更改此表以使用FileStream?所以它会:
[Key] uniqueidentifier rowguidcol not null
constraint DF_File_Key default newid()
constraint UQ_File_Key unique ([Key]),
和
) filestream_on ???
更新
我有以下TSQL:
exec sp_configure filestream_access_level, 2
reconfigure
alter table dbo.Files
set (filestream_on = 'default')
alter table dbo.Files
alter column [Key] add rowguidcol;
alter table dbo.Files
alter column Content filestream;
alter table dbo.Files
add constraint DF__File__Content default (0x),
constraint DF__File__Key default newid(),
constraint UQ__File__Key unique ([Key]);
go
但是当我运行它时,我收到错误: 用于定义' TABLE'的语法不正确约束
我正在使用"默认"因为我想使用默认的文件组。
我错过了什么?
答案 0 :(得分:3)
来自msdn:
SET ( FILESTREAM_ON = { partition_scheme_name | filestream_filegroup_name | "default" | "NULL" } )
Applies to: SQL Server 2008 through SQL Server 2016.
Specifies where FILESTREAM data is stored.
ALTER TABLE with the SET FILESTREAM_ON clause will succeed only if the table has no FILESTREAM columns. The FILESTREAM columns can be added by using a second ALTER TABLE statement.
默认情况下,TEXTIMAGE_ON
用于具有大列的表(nvarchar(max),varbinary(max)等,如上所述here:
TEXTIMAGE_ON is not allowed if there are no large value columns in the table. TEXTIMAGE_ON cannot be specified if <partition_scheme> is specified. If "default" is specified, or if TEXTIMAGE_ON is not specified at all, the large value columns are stored in the default filegroup. The storage of any large value column data specified in CREATE TABLE cannot be subsequently altered.
)