而不是使用FileStream删除触发器

时间:2010-02-22 11:45:05

标签: sql-server-2008 triggers filestream

为什么我不能在具有varbinary filestream列的表上使用而不是删除触发器?

是否有解决方法?

我想在执行删除命令时更新字段。

由于

2 个答案:

答案 0 :(得分:1)

您可以创建两个表而不是一个:

CREATE TABLE [dbo].[FileStreams](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [RowGuid] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
    [Data] [varbinary](max) FILESTREAM  NULL,
    CONSTRAINT [PK_FileStreams] 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],
    UNIQUE NONCLUSTERED 
    (
        [RowGuid] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] FILESTREAM_ON [FilestreamGroup]
GO

CREATE TABLE [dbo].[Files](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](1024) NULL,
    [FileStreamId] [int] NOT NULL,
    CONSTRAINT [PK_Files] 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]
GO

ALTER TABLE [dbo].[Files]  WITH CHECK ADD  CONSTRAINT [FK_Files_FileStreams] FOREIGN KEY([FileStreamId])
REFERENCES [dbo].[FileStreams] ([Id])
GO

ALTER TABLE [dbo].[Files] CHECK CONSTRAINT [FK_Files_FileStreams]
GO

外键必须是NO ACTION。它允许您为表文件

创建INSTEAD OF触发器

答案 1 :(得分:0)

文件流表通常不支持所有类型的INSTEAD OF触发器 - 在这种情况下,DELETE也没有区别。原因可能是在UPDATE触发器和带外更新(来自.Net或Win32)的情况下它会有非常复杂的语义。

如果您提供有关您的方案的更多详细信息,那么也许有人可以为您提供解决方法。