Generate SQL Server Delete Cascade triggers To run it: 1) bring up the Script Explorer 2) right click on "User Defined" and select "New Script" 3) copy/paste the attachment into the edit control 4) hit the run button (the first icon in the toolbar above the edit control) Note: you can undo/redo the effects of this script as with any Model changes /********** start of script *************/ Function RelDeleteStmt(Relation, NumTabs) Set FKMembers = Relation.Children("FK Member") If FKMembers.Count = 0 Then Exit Function End If Set ChildTable = Relation.Owner RelDeleteStmt = Tabs(NumTabs) + "delete " + ChildTable.Name + vbLf RelDeleteStmt = RelDeleteStmt + Tabs(NumTabs + 1) + "from " + ChildTable.Name + ", deleted" + vbLf RelDeleteStmt = RelDeleteStmt + Tabs(NumTabs + 1) + "where" + vbLf For Each FKMember In FKMembers Set ChildColumn = FKMember.Property("Child Column").AsObject Set ParentColumn = FKMember.Property("Parent Column").AsObject RelDeleteStmt = RelDeleteStmt + Tabs(NumTabs + 2) + ChildTable.Name + "." + ChildColumn.Name + " = deleted." + ParentColumn.Name + vbLf Next End Function Sub Evaluate_OnLoad() Set Context = CreateObject("SCF.ScriptContext") Set Document = Context.ScriptDocument Set ThisScript = Context.Object Set Options = Context.Options Set Model = ThisScript.Model For Each Table In Model.AsObject.Children("Table") If Table.HasProperty("Parent To Relations") Then RelStmts = "" For Each RelationProp in Table.Property("Parent To Relations").AsVector Set Relation = RelationProp.AsObject If Relation.Property("Delete Rule").AsString = "Cascade" Then Stmt = RelDeleteStmt(Relation, 2) If Stmt <> "" Then RelStmts = RelStmts + vbLf + Stmt End If End If Next If Table.HasProperty("Special Trigger Code") Then RelStmts = RelStmts + vbLf + Table.Property("Special Trigger Code").AsString End If If RelStmts <> "" Then Document.Write("create trigger tD_" + Table.Name + " on " + Table.Name + " for DELETE as" + vbLf) Document.Write("begin" + vbLf) Document.Write(" declare @errno int," + vbLf) Document.Write(" @errmsg varchar(255)" + vbLf + vbLf) Document.Write(RelStmts + vbLf) Document.Write(" return" + vbLf) Document.Write("error:" + vbLf) Document.Write(" raiserror @errno @errmsg" + vbLf) Document.Write(" rollback transaction" + vbLf) Document.Write("end" + vbLf) Document.Write("go" + vbLf) End If End If Next End Sub