0

I have two tables CrossDBTrigTest_1 and CrossDBTrigTest_2 on same SQL Server instance.

The databases both have a table called Employee.

I wrote the following trigger on the Employee table CrossDBTrigTest_1 db:

Create Trigger [dbo].[CrossDBInsert] on [dbo].[employee] after insert
AS 
Begin
  Set nocount on

  Insert into CrossDBTrigTest_2.employee(FirstName, LastName, Date) 
    SELECT inserted.FirstName, inserted.LastName, getdate() 
    FROM inserted
End

but the Insert statement fails with message:

Msg 208, Level 16, State 1, Procedure CrossDBInsert, Line 5
Invalid object name 'CrossDBTrigTest_2.employee'.

How do I enable cross database triggers in situations like this??

2 Answers 2

8

Shouldn't

  CrossDBTrigTest_2.employee(FirstName,LastName,Date)

be

  CrossDBTrigTest_2.dbo.employee(FirstName,LastName,Date)

???

Sign up to request clarification or add additional context in comments.

Comments

3

Use

CrossDBTrigTest_2..employee

as table name. Note two dots instead of one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.