Q:

Use trigger to act as foreign key across 2 different servers

I'm trying to replicate a foreign key across two servers using trigger. I know using trigger across 2 servers is not the best practice but my company on gives me read-only access to their database which I need to relate to my application. 
I have DB1 which is my local database and it is attached to DB2 using linked server. I want trigger to check if a specific ID from a DB2_table on DB2 exists before executing an INSERT on DB1_table where the ID from DB2_table will act as a foreign key.
CREATE TRIGGER trigger_DB1_Table_Insert
   @ID
BEFORE INSERT ON DB1_Table
AS
BEGIN
   if exists(Select ID from DB2_Table where ID = @ID)
   --execute insert 
END
GO

A:

I would actually recommend using a check constraint instead of a trigger.  Check Constraints are designed to enforce data integrity and are a semantically better option.  The example below creates some working tables, then creates a function which will check if the record exists in the other table.
The check constraint then uses the function and returns an error if the value doesn't exist.
CREATE TABLE dbo.OtherTable(
    id              INT 
)

CREATE TABLE dbo.a(
    id              INT     IDENTITY(1,1)
    ,OtherTableId   INT
)

GO

INSERT INTO OtherTable (id) VALUES (1), (2), (3)
GO

-- Function will check if the ID exists in the other table
CREATE FUNCTION dbo.CheckOtherTableId(
     @OtherTableId          INT
)
RETURNS BIT 
AS BEGIN
    RETURN
    (
        SELECT 
            CASE 
                WHEN EXISTS 
                    (
                        SELECT  1
                        FROM    OtherTable
                        WHERE   id = @OtherTableId
                    )
                    THEN 1 
                    ELSE 0 
            END
    )
END
GO

-- Add check constraint
ALTER TABLE a  WITH CHECK 
    ADD CONSTRAINT [CK_OtherTable] CHECK  (1=dbo.CheckOtherTableId(OtherTableId))
GO

-- Test should work
INSERT INTO a (OtherTableId) values (1)
Go

-- Test should fail
INSERT INTO a (OtherTableId) values (8)
GO

