Relationship & Trigger

Hi,

My current data modeler is Erwin and I’m evaluating Toad Data Modeler.

I’d like to know if it is possible to generate triggers from the relationships instead of creating foreign key constraints.

For example, if I define a relationship with cascade delete between my_table and my_table_2, I’d like to have an auto-generated trigger such as:

create trigger [dbo].[tD_my_table] on [dbo].[my_table] for DELETE as
begin
delete my_table_2
from my_table_2,deleted
where
my_table_2.fk_my_table_pk = deleted.my_table_pk
end

Hello Andrea,

Thank you for your interest. I’m afraid referential integrity triggers are currently not supported in Toad Data Modeler. However, you can always put your feature ideas into the Idea Pond. The most voted ideas are reviewed by the developers and most of them get implemented in future versions of Toad Data Modeler.

Regards,

Lukas

Hi,
Is there any new implementation regarding my request?
Alternatively, is there a workaround, like some macro?
Thanks
Andrea

Hello Andrea,
there are no native implementation of generation triggers for a referential integrity, but it is possible by customization.
There are two possible ways.

  1. Create macro, which will create triggers in TDM models according to relationships. In this case you run the macro and it will create update/delete triggers in your model by the current state. You can manually edit these triggers etc. Disadvantage is that these triggers are not bind to relationships, so any change in relationship dwill not change triggers automatically.

  2. Rewrite Generator to generate sql code for create triggers instead foreign keys. In this case it will generate create statements for triggers each time when you generate SQL code for relationships. Triggers will not be in model, but it will be generated each time by actual state in model.

Presume that you are use SQL Server.
I attached zip archiv. In this zip you can find

  • CreateRITriggersOR.txg
  • CreateRITriggersMS.txg
  • GeneratorRIEntityTriggers.txg

Zip archiv download here ReferentialIntegrity.zip
This is just draft not finished packages. You need modify it by your preferences.

CreateRITriggersOR.txg
This package contains macro which can create triggers for relationship. You can right click on relationship on designer and in popup menu you will see this macro. This macro is available too from main menu - Macros. In this case it will create triggers for all relationships in model.

CreateRITriggersMS.txg
This packages is just conversion previous to MS. It has not fully changed for some SQL server specific, use it as base if you would like go by this way.

GeneratorRIEntityTriggers.txg
This package contains basic modification for generator of SQL Server. Instead code for foreign keys it will generate "Code for triggers". You need modify method below to get requested result.

function CreateRelation(relation)
{
  return "Code for triggers";
};

Note: For customization in TDM you need switch on expert mode from settings.

if you have some questions please don't hesitate to ask us.

Best regards Petr