SQL Server 2014:更新File_Stream.PathName()时的FileTable触发器

时间:2016-02-19 22:48:52

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

我有一个FileTable FT和另一个表AT。在AT中,我在FT中扩展了文件的元数据属性。

我尝试创建一个触发器ON FT FOR UPDATE,它将更新AT中的文件路径。

以下是我尝试的内容:

ALTER TRIGGER [dbo].[u_filepath] 
ON [FileDB].[dbo].[FT] 
FOR UPDATE
AS
    Declare @newpath nvarchar(1000)
    Declare @oldpath nvarchar(1000)

    select @newpath = file_stream.pathname()
    from inserted

    select @oldpath = file_stream.pathname()
    from deleted

    update AT
    set [Path] = @newpath
    where [Path] = @oldpath
GO

当我执行查询时,它会旋转。我计划让它一夜之间运行,以防它决定做某事。

我希望Path中的AT列从file_stream.PathName()更新为更新的FT

触发器是否合乎逻辑?

我应该将file_stream BLOB存储在AT Path列而不是实际路径吗?

1 个答案:

答案 0 :(得分:1)

您的触发器有 MAJOR 缺陷,因为您似乎认为它将被称为每行一次 - 这是的情况。

触发器会在每个语句时触发,因此,如果导致此触发器的2016-03-01 18:59:40 11872 [ERROR] InnoDB: File .\newdb\answer.ibd: 'open' returned OS error 1379. Cannot continue operation 2016-03-01 19:00:16 2eb8 InnoDB: Warning: Using innodb_additional_mem_pool_size is DEPRECATED. This option may be removed in future releases, together with the option innodb_use_sys_malloc and with the InnoDB's internal memory allocator. 2016-03-01 19:00:16 11960 [Note] InnoDB: Using mutexes to ref count buffer pool pages 2016-03-01 19:00:16 11960 [Note] InnoDB: The InnoDB memory heap is disabled 2016-03-01 19:00:16 11960 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions 2016-03-01 19:00:16 11960 [Note] InnoDB: Memory barrier is not used 2016-03-01 19:00:16 11960 [Note] InnoDB: Compressed tables use zlib 1.2.3 2016-03-01 19:00:16 11960 [Note] InnoDB: Using generic crc32 instructions 2016-03-01 19:00:16 11960 [Note] InnoDB: Initializing buffer pool, size = 16.0M 2016-03-01 19:00:16 11960 [Note] InnoDB: Completed initialization of buffer pool 2016-03-01 19:00:26 2eb8 InnoDB: Operating system error number 1179 in a file operation. InnoDB: Some operating system error numbers are described at InnoDB: http://dev.mysql.com/doc/refman/5.6/en/operating-system-error-codes.html InnoDB: Operation open to file os\os0file.cc and at line 2041 2016-03-01 19:00:26 11960 [ERROR] InnoDB: File G:\Xampp\mysql\data\ibdata1: 'open' returned OS error 1379. Cannot continue operation 语句触发插入25行,则会触发触发器一次,但UPDATEDeleted伪表将包含25行。

您的代码会选择这25行中的哪一行?

Inserted

这是非确定性的,你会得到一行,你将忽略所有其他行

您需要重写触发器才能将此考虑在内 - 使用基于集合的方法更新数据 - 而不是基于行的数据 - 如下所示:

select @newpath = file_stream.pathname()
from inserted