触发器未在另一个数据库上插入数据的问题

时间:2014-11-13 14:26:01

标签: sql-server triggers

我有一个更新另一个数据库中的表的触发器。我已经检查了select语句,它确实返回了正确的值,但它根本没有用任何东西来更新目标表。

USE [Dashboard]
GO
/****** Object:  Trigger [dbo].[UpdateUser]    Script Date: 13/11/2014 12:15:04 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER TRIGGER [dbo].[UpdateUser]
   ON  [dbo].[Dashboard]
   FOR INSERT
AS 
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;


    INSERT INTO Portal.dbo.Dashboards
            (Company, UserID, DashboardID)
    SELECT  LEFT(EA.roleOrUser,CHARINDEX(',',EA.roleOrUser)-1), -- Company - nvarchar(250)
             RIGHT(EA.roleOrUser,CHARINDEX(',',EA.roleOrUser)-4), -- UserID - int
             i.id  -- DashboardID - int

    FROM Inserted i
    INNER JOIN dbo.EntityAuth EA
    ON i.id = EA.entityid 


END

1 个答案:

答案 0 :(得分:0)

检查目标数据库中的用户权限。触发器在启动触发器的用户的上下文中触发。