ER/Studio - Embarcadero Technologies Product Documentation

ER/Studio - Embarcadero Technologies Product Documentation ER/Studio - Embarcadero Technologies Product Documentation

docs.embarcadero.com
from docs.embarcadero.com More from this publisher
24.12.2012 Views

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

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

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!