Previous Topic: Create a Relationship Override Trigger TemplateNext Topic: Table Override Templates


Example: Relationship Override Template

The following example shows the template code for the Relationship Override of the Parent-Delete RESTRICT trigger. The top section shows a portion of the template, the center section shows the expanded code of the same portion, and the bottom section shows the complete trigger template expanded for a SQL Server. The template code is for the relationship override on CUST_ORDER-ORDER_LINE relationship using the Parent-Delete RESTRICT trigger.

/* ERwin Built-in %Datetime */
    /* %Parent %VerbPhrase %Child ON PARENT Delete RESTRICT */
    update %Parent
      set order_status = 'outstanding'
      from %Parent,deleted,%Child
        where
          /* %%JoinPKPK(%Parent,deleted) */
          %JoinPKPK(%Parent,deleted) and
          /* %%JoinFKPK(%Child,deleted) */
          %JoinFKPK(%Child,deleted)


/* ERwin Built-in Mon May 09 07:52:30 2007 */
    /* CUST_ORDER contains ORDER_LINE ON PARENT Delete RESTRICT */
    update CUST_ORDER
      set order_status = 'outstanding'
      from CUST_ORDER,deleted,ORDER_LINE
        where
          /* %JoinPKPK(CUST_ORDER,deleted) */
          CUST_ORDER.order_id = deleted.order_id and
          /* %JoinFKPK(ORDER_LINE,deleted) */
          ORDER_LINE.order_id = deleted.order_id


create trigger tD_CUST_ORDER on CUST_ORDER for Delete as
/* ERwin Built-in Mon May 09 07:55:10 2007 */
/* Delete trigger on CUST_ORDER */
begin
  declare  @errno   int,
           @errmsg  varchar(255)
    /* ERwin Built-in Mon May 09 07:55:10 2007 */
    /* CUST_ORDER contains ORDER_LINE ON PARENT Delete RESTRICT */
    update CUST_ORDER
      set order_status = 'outstanding'
      from CUST_ORDER,deleted,ORDER_LINE
        where
          /* %JoinPKPK(CUST_ORDER,deleted) */
          CUST_ORDER.order_id = deleted.order_id and
          /* %JoinFKPK(ORDER_LINE,deleted) */
          ORDER_LINE.order_id = deleted.order_id
    /* ERwin Built-in Mon May 09 07:55:10 2007 */
    return
error:
    raiserror @errno @errmsg
    rollback transaction
end
go

More information:

Relationship Override Templates