是否可以从其他数据库 table 中的触发器调用 UDF?

Is it possible to call a UDF from a trigger in other database table?

我有 2 个数据库,比如 DB1 和 DB2。 DB1 包含一个 table,比如 MyTable,而 DB2 包含一个 UDF,比如 MyFunction。

我需要在 DB1 的 MyTable table 中创建一个插入触发器。该触发器应该调用 DB2 中的 UDF。

我在触发器中试过这个:

    DECLARE @result INT
    SELECT @result = DB2.[dbo].[MyFunction]

但这不起作用。

有办法吗?

问候 海梅

当我在不同的数据库中创建触发器并引用标量函数时没有所需的尾随 ()(根据原始 post)

CREATE TRIGGER tTEST on MD.Table
FOR INSERT
AS
SELECT DB2.dbo.LocalDateTime

我明白了

Msg 4104, Level 16, State 1, Procedure tTEST, Line 4 [Batch Start Line 185] The multi-part identifier "DB2.dbo.LocalDateTime" could not be bound.

我想这就是您遇到的错误?

因此添加所需的括号:

CREATE TRIGGER tTEST on MD.Table
FOR INSERT
AS
SELECT DB2.dbo.LocalDateTime()