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 Notes • You can choose to launch your preferred SQL editor when editing functions and procedures. Using the Tools tab of the Options Editor, you can enter the name and location of the SQL editor that will launch and manage the SQL ER/Studio outputs. Click Tools > Options > Tools > ISQL Path. • For all new models you can choose: • To display the schema object description or its associated symbol; click Tools > Options > Display and then select the desired display mode. • To hide invalid schema objects; click Tools > Options > Schema Objects and then select Hide Invalid Schema Object Bitmap. • For the current data model, you can choose: • To display the schema objects or objects relationships, and object definition or object symbol; click View > Diagram And Object Display Options > Schema Object and then select the desired display options. • What to display when you mouse over a schema object; click Tools > Options > Diagram > Schema Object Display and choose to display the object description or its associated DDL. • For physical models, you can enter SQL to be applied before and after the CREATE OBJECT clause in the CREATE TABLE statement. Click Model > Model Properties > PreSQL & Post SQL. • The sample physical model for SQL Server 200 in Northwindl.dm1 provides some good examples of how SQL procedures can be used. Import an SQL Procedure 1 In the Data Model Explorer, expand the Physical Main Model, right-click the Procedures node, and then click New Procedure. 2 On the Description tab, click Import and then type, or browse to and then select the name of SQL procedure file you want to import. 3 Complete the Procedure SQL Editor and then click OK to create the procedure. Export an SQL Procedure 1 In the Data Model Explorer, expand the Physical Main Model, right-click the Procedures node, and then click New Procedure. 2 On the Description tab, click Export and then type, or browse to and then select the name of the SQL procedure file name where you want to save the SQL procedure. 3 Complete the Procedure SQL Editor and then click OK to create the procedure. Creating and Editing Triggers Triggers are code objects associated with a table that automatically execute when the table is modified by an SQL INSERT, UPDATE, or DELETE statement. Triggers can contain complex SQL statements, such as those required to query other tables, but cannot accept parameters or arguments, and cannot perform commit or rollback operations. They are also subject to coding errors like every other script or application. EMBARCADERO TECHNOLOGIES > ER/STUDIO® 8.0.3 USER GUIDE 186
USING ER/STUDIO > DEVELOPING THE PHYSICAL MODEL Because triggers are customizable and execute automatically, they are often used to: • Enforce referential integrity rules. For example, when a new customer in the eastern territory is added to the customer table, the new customer information is also added to the table for the sales representative handling that region. • Enforce business rules on table data. For example, restricting an order insertion based on the customer’s account status. If the customer’s payment is overdue or the order exceeds the customer’s credit limit, the order is rejected. • Synchronize information in another table when a table is updated. For example, you can create a delete trigger on the product table that the trigger uses to locate and delete matching rows in the sales table and pending orders table. • Initiate an action external to the SQL Server when an update occurs. For example, when a new employee is hired and added into the employees table, an e-mail is sent to the human resources department that prompts them to perform certain actions like arranging desk space and computer equipment, and ensuring all that all required paperwork is sent to the new employee and is returned completed to the human resources department. • Prevent some types of operations, such as UPDATEs. For example, a trigger can roll back updates that attempt to apply a bonus (stored in the renumeration table) to employees (stored in the persons table) who work less than 16 hours a week. You can view the triggers associated with your models from the Triggers node in the Data Model Explorer, but to create or edit triggers, you must use the Triggers tab of the table with which you want to associate the trigger. The generated trigger code is customized for each target database platform. ER/Studio uses templates to implement trigger code generation. SQL Procedures can be triggers that are a special type of procedure. ER/Studio supports the following trigger types: • Referential Integrity Triggers ensure implied relationships in the database are enforced, by preventing users from creating discrepancies in the database. They inform the database how to manage or process the procedural SQL commands, which enforce the business rules of an organization. ER/Studio defines Referential Integrity Triggers by establishing insert, update and delete options between parent and child tables. On the Trigger tab of the Relationship Editor, you can define the level of referential integrity and SQL insert, update, and delete behaviors. For more information, see Create a Referential Integrity Trigger. • User-Defined Triggers are usually customized for special situations to override the default capabilities of database generated code. User-defined triggers are closely tied to DBMS-specific code, and therefore, are implemented only in physical models. There are three types of user-defined triggers: • Scripted Triggers that are written in the raw procedural code of the database such as Oracle's PL/SQL or Microsoft's Transact-SQL. You can reverse-engineer these objects if they exist on the database. You can also display them in the Data Model Window. Reverse-engineered triggers have table names and other object references hard-coded into their underlying code. For more information, see Create a Scripted User-Defined Trigger. • Templated Triggers that do not have names of specific objects the trigger references, such as table names and specific columns hard-coded into their underlying code. This enables these triggers to be reused across various objects of an application, and the body of the trigger code to be reused across models. For more information, see Create a Templated User-Defined Trigger. • Reusable Triggers that can perform actions against any number of tables. For more information, see Create a Reusable User-Defined Trigger. Notes • To view triggers on the Data Model Window, you must enable them. To display triggers, click Tools > Options > Schema Objects. EMBARCADERO TECHNOLOGIES > ER/STUDIO® 8.0.3 USER GUIDE 187
- Page 135 and 136: USING ER/STUDIO > DEVELOPING THE LO
- Page 137 and 138: USING ER/STUDIO > DEVELOPING THE LO
- 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: USING ER/STUDIO > DEVELOPING THE PH
- Page 189 and 190: USING ER/STUDIO > DEVELOPING THE PH
- Page 191 and 192: 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
USING <strong>ER</strong>/STUDIO > DEVELOPING THE PHYSICAL MODEL<br />
Because triggers are customizable and execute automatically, they are often used to:<br />
• Enforce referential integrity rules. For example, when a new customer in the eastern territory is added to the<br />
customer table, the new customer information is also added to the table for the sales representative handling<br />
that region.<br />
• Enforce business rules on table data. For example, restricting an order insertion based on the customer’s<br />
account status. If the customer’s payment is overdue or the order exceeds the customer’s credit limit, the order<br />
is rejected.<br />
• Synchronize information in another table when a table is updated. For example, you can create a delete trigger<br />
on the product table that the trigger uses to locate and delete matching rows in the sales table and pending<br />
orders table.<br />
• Initiate an action external to the SQL Server when an update occurs. For example, when a new employee is<br />
hired and added into the employees table, an e-mail is sent to the human resources department that prompts<br />
them to perform certain actions like arranging desk space and computer equipment, and ensuring all that all<br />
required paperwork is sent to the new employee and is returned completed to the human resources<br />
department.<br />
• Prevent some types of operations, such as UPDATEs. For example, a trigger can roll back updates that<br />
attempt to apply a bonus (stored in the renumeration table) to employees (stored in the persons table)<br />
who work less than 16 hours a week.<br />
You can view the triggers associated with your models from the Triggers node in the Data Model Explorer, but to<br />
create or edit triggers, you must use the Triggers tab of the table with which you want to associate the trigger.<br />
The generated trigger code is customized for each target database platform. <strong>ER</strong>/<strong>Studio</strong> uses templates to implement<br />
trigger code generation. SQL Procedures can be triggers that are a special type of procedure.<br />
<strong>ER</strong>/<strong>Studio</strong> supports the following trigger types:<br />
• Referential Integrity Triggers ensure implied relationships in the database are enforced, by preventing users from<br />
creating discrepancies in the database. They inform the database how to manage or process the procedural SQL<br />
commands, which enforce the business rules of an organization. <strong>ER</strong>/<strong>Studio</strong> defines Referential Integrity Triggers<br />
by establishing insert, update and delete options between parent and child tables.<br />
On the Trigger tab of the Relationship Editor, you can define the level of referential integrity and SQL insert,<br />
update, and delete behaviors. For more information, see Create a Referential Integrity Trigger.<br />
• User-Defined Triggers are usually customized for special situations to override the default capabilities of<br />
database generated code. User-defined triggers are closely tied to DBMS-specific code, and therefore, are<br />
implemented only in physical models. There are three types of user-defined triggers:<br />
• Scripted Triggers that are written in the raw procedural code of the database such as Oracle's PL/SQL or<br />
Microsoft's Transact-SQL. You can reverse-engineer these objects if they exist on the database. You can also<br />
display them in the Data Model Window. Reverse-engineered triggers have table names and other object<br />
references hard-coded into their underlying code. For more information, see Create a Scripted User-Defined<br />
Trigger.<br />
• Templated Triggers that do not have names of specific objects the trigger references, such as table names<br />
and specific columns hard-coded into their underlying code. This enables these triggers to be reused across<br />
various objects of an application, and the body of the trigger code to be reused across models. For more<br />
information, see Create a Templated User-Defined Trigger.<br />
• Reusable Triggers that can perform actions against any number of tables. For more information, see Create a<br />
Reusable User-Defined Trigger.<br />
Notes<br />
• To view triggers on the Data Model Window, you must enable them. To display triggers, click Tools > Options ><br />
Schema Objects.<br />
EMBARCAD<strong>ER</strong>O TECHNOLOGIES > <strong>ER</strong>/STUDIO® 8.0.3 US<strong>ER</strong> GUIDE 187