SQL触发器代码运行无错误但无输出

时间:2018-11-18 09:46:14

标签: sql-server ssms database-trigger

我在同一服务器TEST1和TEST2中有两个数据库

在TEST1中,我有一个名为dbo.TB_EVENT_LOG的表 列是

[nEventLogIdn]
[nDateTime]
[nReaderIdn]
[nEventIdn]
[nUserID]
[nIsLog]
[nTNAEvent]
[nIsUseTA]
[nType]

在Test2中,我有一个名为dbo.AccessLog的表 列是

[RCDID]
[EmployeeID]
[LogDate]
[LogTime]
[TerminalID]
[InOut]

我想要做的是在插入或更新任何数据到test1 dbo.TB_EVENT_LOG时触发一个触发器。并将数据从dbo.TB_EVENT_LOG(nDateTime,nReaderIdn,nUserID)的特定列插入到dbo.AccessLog(LogDate,TerminalID,EmployeeID)

触发器在dbo.TB_EVENT_LOG表中运行

这是我到目前为止的触发代码

USE [test1]
GO
/****** Object:  Trigger [dbo].[coveter]    Script Date: 11/18/2018 2:25:13 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      
-- Create date: 18/11/2018
-- Description: 
-- =============================================
ALTER TRIGGER [dbo].[coveter] 
   ON  [dbo].[TB_EVENT_LOG] 
   AFTER INSERT, UPDATE, DELETE
AS 
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    insert into test2.dbo.AccessLog
    (
        [LogDate],
        [LogTime],
        [TerminalID],
        [EmployeeID]
    )

    select [nDateTime], [nDateTime], [nReaderIdn],[nUserID] from dbo.TB_EVENT_LOG

END

代码运行没有任何错误,但我无法获得想要的结果。有帮助吗?

谢谢。

0 个答案:

没有答案