Copy Code Trigger Definition

        
CREATE trigger dbo.TR_BANKACCOUNTDEPOSIT_VALIDATE on dbo.BANKACCOUNTDEPOSIT for INSERT, UPDATE not for replication as
BEGIN
  set nocount on;
  
  if (select count(ID) from inserted) > 0 and
     (not exists(select D.ID from INSERTED D
    inner join dbo.BANKACCOUNTTRANSACTION T on D.ID = T.ID
    inner join dbo.BANKACCOUNT BA on BA.ID = T.BANKACCOUNTID
    inner join dbo.PDACCOUNTSYSTEM S on S.ID = BA.PDACCOUNTSYSTEMID
    inner join dbo.CURRENCYSETTRANSACTIONCURRENCY C on C.CURRENCYSETID = S.CURRENCYSETID
    where C.CURRENCYID = D.TRANSACTIONCURRENCYID or D.TRANSACTIONCURRENCYID is null))
    begin
      RAISERROR ('ERR_BANKACCOUNTDEPOSIT_TRANSACTIONCURRENCYID_NOTINCURRENCYSET',  16, 1)
          ROLLBACK TRANSACTION
    end
END