ER/Studio - Embarcadero Technologies Product Documentation
ER/Studio - Embarcadero Technologies Product Documentation ER/Studio - Embarcadero Technologies Product Documentation
USING ER/STUDIO > DEVELOPING THE PHYSICAL MODEL • Set Null: The trigger verifies the existence of the foreign key values in the parent table's primary key. If the values cannot be validated, then the trigger sets the foreign key value to null in the child table and then updates or deletes the parent. For example, you have a parent table persons and a child table tasks, which through a mandatory relationship share an id. By using a Set Null trigger you can allow the user to insert data into the tasks table that contains an id for which their is no corresponding value in the persons table. The database will not throw a referential integrity error in this case. • Set Default: Sets the foreign key to its DEFAULT value, then updates or deletes the parent. • Restrict: The trigger verifies the existence of foreign key values in the parent table's primary key. If the values cannot be validated, then the trigger prevents the insertion, update or deletion of data. For example, you have a parent table persons and a child table tasks, which through a mandatory relationship share an id. By using a Restrict trigger you can prevent the user from inserting data into the tasks table that contains an id for which their is no corresponding value in the persons table. The database will throw a referential integrity error in this case. • Cascade: If a primary key is updated or deleted, the trigger cascades that modification to corresponding foreign key values in dependent tables. Create a Scripted User-Defined Trigger 1 On the Data Model Window or the Data Model Explorer, select the table on which you want to create a Trigger. 2 Select Edit > Edit Database Table. TIP: Alternatively, on the Data Model Window, open the Table Editor by double-clicking the table or right-clicking the object and then selecting Edit Table. 3 On the Table Editor, click the Dependencies tab. 4 Click the Add button and then select Triggers > Scripted. 5 Complete the Trigger Editor and then click Finish to create the trigger. The following describe options that require additional explanation: • In order for code to be generated for procedural logic such as triggers and procedures, the results of the trigger must be stored in a variable called resultstring. For example, in the Northwind.dm1 sample model, the Data Dictionary lists a reusable trigger, SYSUPDATE, for the the Oracle platform. The code for this trigger includes the following statement, which is required for code to be generated for the trigger: resultstring = trigBody • The Trigger Editor includes find and replace functionality for working with SQL text strings. • Name: Lets you enter a trigger name or edit the existing one. SQL tab Lets you enter a CREATE TRIGGER statement for the trigger, or edit the existing script. If you do not want to enter an SQL script, you can use the Import button to import it. • Export: Lets you export the SQL script to a *.sql file. This is useful for when you want to create additional triggers based on the one you are currently creating. You can export the code, and later import it into another procedure. When you click Export, the Save As dialog box opens. Enter the file name. ER/Studio saves the files in the Model folder, if you want to save your files in a different folder, browse and locate it. • Import: Lets you import *.sql files. When you click Import, the Open dialog box opens. You can enter the name of the *.sql file, or browse and locate it. • Validate: Lets you validate the SQL script. If ER/Studio detects any errors, it returns them in a message box. Errors include the error type, line, and column information. EMBARCADERO TECHNOLOGIES > ER/STUDIO® 8.0.3 USER GUIDE 190
USING ER/STUDIO > DEVELOPING THE PHYSICAL MODEL Description tab Includes a text box where you can enter a Trigger description. Attachment Bindings tab Bind an external piece of information, or attachment to the trigger. You can also remove an attachment from an object, override an attachment binding’s default value, or change the position of a bound attachment. To override the value of the attachment you have moved to the Selected Attachments grid, double-click the Value field of the target attachment. ER/Studio opens the Value Override Editor or a list depending on the attachment datatype. Attachments are created in the Attachments folder of the Data Dictionary. For more information, see Attaching External Documents to the Data Model. Create a Templated User-Defined Trigger 1 In the Data Model Explorer, expand the Physical Main Model, right-click the Triggers node, and then click New Trigger. 2 Complete the Trigger Wizard and then click Finish to create the trigger. TIP: Once you have created the auxiliary table, you can edit it by right-clicking the auxiliary table you want to change, and then selecting Edit Auxiliary Table. The following describe options that require additional explanation: • The Trigger Editor includes find and replace functionality for working with SQL text strings. • In order for code to be generated for procedural logic such as triggers and procedures, the results of the trigger must be stored in a variable called resultstring. For example, in the Northwind.dm1 sample model, the Data Dictionary lists a reusable trigger, SYSUPDATE, for the the Oracle platform. The code for this trigger includes the following statement, which is required for code to be generated for the trigger: resultstring = trigBody Description page/tab Enter or edit a definition for the description. If the target database supports it, ER/Studio adds this definition as a comment when generating SQL code. Attachment Bindings tab Bind an external piece of information, or attachment to the trigger. You can also remove an attachment from an object, override an attachment binding’s default value, or change the position of a bound attachment. To override the value of the attachment you have moved to the Selected Attachments grid, double-click the Value field of the target attachment. ER/Studio opens the Value Override Editor or a list depending on the attachment datatype. Attachments are created in the Attachments folder of the Data Dictionary. For more information, see Attaching External Documents to the Data Model. Create a Reusable User-Defined Trigger Reusable user-defined triggers are created in the Data Dictionary. For more information, see Create and Edit Reusable Triggers Creating and Editing Functions Functions are subroutines that you define. Functions can be written in a programming language such as C, COBOL, or Java that returns a scalar value or a complete table, or they can call another function, or they can be written in SQL and return a scalar value. Functions are useful for reusable application logic. You can use functions to determine the best methods for controlling access and manipulation of the underlying data contained in an object. Functions accept a number of parameters and pass a single value back to the calling program. Functions can be used in the database to check the validity of the data being entered. For example, functions can be used to validate zip codes. By invoking a routine with the zip code, the function can return a true or false value based on if the zip code is valid. EMBARCADERO TECHNOLOGIES > ER/STUDIO® 8.0.3 USER GUIDE 191
- Page 139 and 140: USING ER/STUDIO > DEVELOPING THE LO
- Page 141 and 142: USING ER/STUDIO > DEVELOPING THE LO
- Page 143 and 144: USING ER/STUDIO > DEVELOPING THE PH
- Page 145 and 146: USING ER/STUDIO > DEVELOPING THE PH
- Page 147 and 148: USING ER/STUDIO > DEVELOPING THE PH
- Page 149 and 150: USING ER/STUDIO > DEVELOPING THE PH
- Page 151 and 152: USING ER/STUDIO > DEVELOPING THE PH
- Page 153 and 154: USING ER/STUDIO > DEVELOPING THE PH
- Page 155 and 156: USING ER/STUDIO > DEVELOPING THE PH
- Page 157 and 158: USING ER/STUDIO > DEVELOPING THE PH
- Page 159 and 160: USING ER/STUDIO > DEVELOPING THE PH
- Page 161 and 162: USING ER/STUDIO > DEVELOPING THE PH
- Page 163 and 164: USING ER/STUDIO > DEVELOPING THE PH
- Page 165 and 166: USING ER/STUDIO > DEVELOPING THE PH
- Page 167 and 168: USING ER/STUDIO > DEVELOPING THE PH
- Page 169 and 170: USING ER/STUDIO > DEVELOPING THE PH
- Page 171 and 172: USING ER/STUDIO > DEVELOPING THE PH
- Page 173 and 174: USING ER/STUDIO > DEVELOPING THE PH
- Page 175 and 176: USING ER/STUDIO > DEVELOPING THE PH
- Page 177 and 178: USING ER/STUDIO > DEVELOPING THE PH
- Page 179 and 180: USING ER/STUDIO > DEVELOPING THE PH
- Page 181 and 182: USING ER/STUDIO > DEVELOPING THE PH
- Page 183 and 184: USING ER/STUDIO > DEVELOPING THE PH
- Page 185 and 186: USING ER/STUDIO > DEVELOPING THE PH
- Page 187 and 188: USING ER/STUDIO > DEVELOPING THE PH
- Page 189: USING ER/STUDIO > DEVELOPING THE PH
- Page 193 and 194: USING ER/STUDIO > DEVELOPING THE PH
- Page 195 and 196: USING ER/STUDIO > DEVELOPING THE PH
- Page 197 and 198: USING ER/STUDIO > DEVELOPING THE PH
- Page 199 and 200: USING ER/STUDIO > DEVELOPING THE PH
- Page 201 and 202: USING ER/STUDIO > DEVELOPING THE PH
- Page 203 and 204: USING ER/STUDIO > DEVELOPING THE PH
- Page 205 and 206: USING ER/STUDIO > DEVELOPING THE PH
- Page 207 and 208: USING ER/STUDIO > DEVELOPING THE PH
- Page 209 and 210: USING ER/STUDIO > DEVELOPING THE PH
- Page 211 and 212: USING ER/STUDIO > DEVELOPING THE PH
- Page 213 and 214: USING ER/STUDIO > DEVELOPING THE PH
- Page 215 and 216: USING ER/STUDIO > DEVELOPING THE PH
- Page 217 and 218: USING ER/STUDIO > DEVELOPING THE PH
- Page 219 and 220: USING ER/STUDIO > DEVELOPING THE PH
- Page 221 and 222: USING ER/STUDIO > WORKING WITH THE
- Page 223 and 224: USING ER/STUDIO > WORKING WITH THE
- Page 225 and 226: USING ER/STUDIO > WORKING WITH THE
- Page 227 and 228: USING ER/STUDIO > WORKING WITH THE
- Page 229 and 230: USING ER/STUDIO > WORKING WITH THE
- Page 231 and 232: USING ER/STUDIO > WORKING WITH THE
- Page 233 and 234: USING ER/STUDIO > WORKING WITH THE
- Page 235 and 236: USING ER/STUDIO > WORKING WITH THE
- Page 237 and 238: USING ER/STUDIO > WORKING WITH THE
- Page 239 and 240: USING ER/STUDIO > WORKING WITH THE
USING <strong>ER</strong>/STUDIO > DEVELOPING THE PHYSICAL MODEL<br />
• Set Null: The trigger verifies the existence of the foreign key values in the parent table's primary key. If the values<br />
cannot be validated, then the trigger sets the foreign key value to null in the child table and then updates or<br />
deletes the parent. For example, you have a parent table persons and a child table tasks, which through a<br />
mandatory relationship share an id. By using a Set Null trigger you can allow the user to insert data into the<br />
tasks table that contains an id for which their is no corresponding value in the persons table. The database will<br />
not throw a referential integrity error in this case.<br />
• Set Default: Sets the foreign key to its DEFAULT value, then updates or deletes the parent.<br />
• Restrict: The trigger verifies the existence of foreign key values in the parent table's primary key. If the values<br />
cannot be validated, then the trigger prevents the insertion, update or deletion of data. For example, you have a<br />
parent table persons and a child table tasks, which through a mandatory relationship share an id. By using a<br />
Restrict trigger you can prevent the user from inserting data into the tasks table that contains an id for which<br />
their is no corresponding value in the persons table. The database will throw a referential integrity error in this<br />
case.<br />
• Cascade: If a primary key is updated or deleted, the trigger cascades that modification to corresponding foreign<br />
key values in dependent tables.<br />
Create a Scripted User-Defined Trigger<br />
1 On the Data Model Window or the Data Model Explorer, select the table on which you want to create a Trigger.<br />
2 Select Edit > Edit Database Table.<br />
TIP: Alternatively, on the Data Model Window, open the Table Editor by double-clicking the table or<br />
right-clicking the object and then selecting Edit Table.<br />
3 On the Table Editor, click the Dependencies tab.<br />
4 Click the Add button and then select Triggers > Scripted.<br />
5 Complete the Trigger Editor and then click Finish to create the trigger.<br />
The following describe options that require additional explanation:<br />
• In order for code to be generated for procedural logic such as triggers and procedures, the results of the<br />
trigger must be stored in a variable called resultstring. For example, in the Northwind.dm1 sample model,<br />
the Data Dictionary lists a reusable trigger, SYSUPDATE, for the the Oracle platform. The code for this trigger<br />
includes the following statement, which is required for code to be generated for the trigger:<br />
resultstring = trigBody<br />
• The Trigger Editor includes find and replace functionality for working with SQL text strings.<br />
• Name: Lets you enter a trigger name or edit the existing one.<br />
SQL tab<br />
Lets you enter a CREATE TRIGG<strong>ER</strong> statement for the trigger, or edit the existing script. If you do not want to<br />
enter an SQL script, you can use the Import button to import it.<br />
• Export: Lets you export the SQL script to a *.sql file. This is useful for when you want to create additional triggers<br />
based on the one you are currently creating. You can export the code, and later import it into another procedure.<br />
When you click Export, the Save As dialog box opens. Enter the file name. <strong>ER</strong>/<strong>Studio</strong> saves the files in the Model<br />
folder, if you want to save your files in a different folder, browse and locate it.<br />
• Import: Lets you import *.sql files. When you click Import, the Open dialog box opens. You can enter the name<br />
of the *.sql file, or browse and locate it.<br />
• Validate: Lets you validate the SQL script. If <strong>ER</strong>/<strong>Studio</strong> detects any errors, it returns them in a message box.<br />
Errors include the error type, line, and column information.<br />
EMBARCAD<strong>ER</strong>O TECHNOLOGIES > <strong>ER</strong>/STUDIO® 8.0.3 US<strong>ER</strong> GUIDE 190