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 • Scripted and templated procedures that can store application code into the database for all applications to used via the CALL statement. For more information, see Creating and Editing Procedures. • Scripted and templated triggers that enforce referential integrity rules; enforce business rules on table data; synchronize information in another table when a table is updated; initiate an action external to the DBMS when an update occurs; and prevent some types of operations, such as UPDATEs. For more information, see Creating and Editing Triggers. • Functions that can execute multiple SQL statements from within an SQL statement. For more information, see Creating and Editing Functions. • Packages that can store together all the code necessary to process SQL statements from a single source file. You can use packages to process and call batches of SQL. For more information, see Creating and Editing Packages. Creating and Editing PreSQL and PostSQL for the CREATE TABLE Statement In the PreSQL & PostSQL tab of the Table Editor you can enter SQL procedures to be applied before and after the CREATE TABLE statement. NOTE: The SQL in the procedure will be validated in context of the table selected and the database platform. 1 In the Data Model Window or Data Model Explorer, double-click a table to launch the Table Editor. 2 Click the PreSQL & PostSQL tab. 3 Enter or edit an SQL procedure to run before the CREATE TABLE statement. 4 Click the PostSQL tab and then enter or edit an SQL procedures to run before the CREATE TABLE statement. 5 Click OK to implement the changes and exit the editor. Creating and Editing Procedures Procedures are reusable blocks of PL/SQL, stored in the database, that applications can call. Procedures streamline code development, debugging and maintenance by being reusable. Procedures can enhance database security by letting you write procedures granting users execution privileges to tables rather than letting them access tables directly. Also, procedures can increase the efficiency of your database. They can consolidate and centralize logic that might otherwise have existed in multiple applications that access the same database, making the code easier to maintain. Since only the procedure executable is stored on the server, decreasing its storage requirements, and the procedure is executed on the server, reducing network traffic. Procedures are similar to functions except that functions can be used within SQL statements, whereas procedures must be invoked using the CALL statement. ER/Studio supports the following procedure types: • Regular or scripted procedures: Specific to the table on which they are created. You can write scripted procedures in SQL You can create a scripted procedure through the Table Editor - Dependencies Tab or though the Procedure SQL Editor, which you can access by double-clicking the procedure name in the Procedures node of the Data Model Explorer. • Templated Procedures: Specific to the table on which they are created or modified. You can write templated procedures in BASIC. Once created, they do not appear in the list of procedures on the Procedures node of the Data Model Explorer. EMBARCADERO TECHNOLOGIES > ER/STUDIO® 8.0.3 USER GUIDE 182

USING ER/STUDIO > DEVELOPING THE PHYSICAL MODEL • Reusable procedures: Created in the data dictionary, reusable procedures can become templated if they are modified through the Table Editor. You can write templated procedures in BASIC. Reusable procedures are templated procedures written in BASIC code. These procedures can be applied to any table, since they use the table’s context in the code. The Reusable Procedure node in the Data Dictionary includes DBMS platform nodes. ER/Studio organizes reusable procedures by platform. When you want to create, edit, or delete a reusable procedure, right-click the target DBMS node and then click the appropriate short cut menu. The following database platforms support Procedures: • IBM DB2 for LUW 5.x, 6.x, 7.x, 8.x, and 9.x • Microsoft Access 6.x and 7.x • Microsoft SQL Server 6.x, 7.x, 2000, 2005, and 2008 • Oracle 7.x, 8.x, 9i, 10g, and 11g • Sybase ASA 6.0, 7.0, 8.0, 9.0, Adaptive Server IQ 12 • Sybase Adaptive Server IQ 12 • Sybase ASE 11.0, 11.5, 11.9, 12.0, 12.5, and 15 TIP: The Northwind.dm1 sample model illustrates how procedures can be used to gather information and perform computations on them to provide summary information. Notes • You can view the templated procedures associated with a table on the Dependencies tab of the Table Editor. • You can view the scripted procedures you create under the Procedures tab of the node. • In order for code to be generated for procedural logic such as triggers and procedures, the results of the code 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 Create a Scripted Procedure 1 In the Data Model Explorer, expand the physical Main Model, right-click the Procedures node, and then click New Procedure. 2 Complete the Procedure SQL Editor and then click Validate to ensure the SQL is valid. 3 Click OK to create the procedure and exit the editor. 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 Procedure. 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 logic 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 SQL page/tab Enter the SQL for the procedure. EMBARCADERO TECHNOLOGIES > ER/STUDIO® 8.0.3 USER GUIDE 183

USING <strong>ER</strong>/STUDIO > DEVELOPING THE PHYSICAL MODEL<br />

• Reusable procedures: Created in the data dictionary, reusable procedures can become templated if they are<br />

modified through the Table Editor. You can write templated procedures in BASIC. Reusable procedures are<br />

templated procedures written in BASIC code. These procedures can be applied to any table, since they use the<br />

table’s context in the code. The Reusable Procedure node in the Data Dictionary includes DBMS platform nodes.<br />

<strong>ER</strong>/<strong>Studio</strong> organizes reusable procedures by platform. When you want to create, edit, or delete a reusable<br />

procedure, right-click the target DBMS node and then click the appropriate short cut menu.<br />

The following database platforms support Procedures:<br />

• IBM DB2 for LUW 5.x, 6.x, 7.x, 8.x, and 9.x<br />

• Microsoft Access 6.x and 7.x<br />

• Microsoft SQL Server 6.x, 7.x, 2000, 2005, and 2008<br />

• Oracle 7.x, 8.x, 9i, 10g, and 11g<br />

• Sybase ASA 6.0, 7.0, 8.0, 9.0, Adaptive Server IQ 12<br />

• Sybase Adaptive Server IQ 12<br />

• Sybase ASE 11.0, 11.5, 11.9, 12.0, 12.5, and 15<br />

TIP: The Northwind.dm1 sample model illustrates how procedures can be used to gather<br />

information and perform computations on them to provide summary information.<br />

Notes<br />

• You can view the templated procedures associated with a table on the Dependencies tab of the Table Editor.<br />

• You can view the scripted procedures you create under the Procedures tab of the node.<br />

• In order for code to be generated for procedural logic such as triggers and procedures, the results of the code<br />

must be stored in a variable called resultstring. For example, in the Northwind.dm1 sample model, the Data<br />

Dictionary lists a reusable trigger, SYSUPDATE, for the the Oracle platform. The code for this trigger includes the<br />

following statement, which is required for code to be generated for the trigger:<br />

resultstring = trigBody<br />

Create a Scripted Procedure<br />

1 In the Data Model Explorer, expand the physical Main Model, right-click the Procedures node, and then click<br />

New Procedure.<br />

2 Complete the Procedure SQL Editor and then click Validate to ensure the SQL is valid.<br />

3 Click OK to create the procedure and exit the editor.<br />

TIP: Once you have created the auxiliary table, you can edit it by right-clicking the auxiliary table you<br />

want to change, and then selecting Procedure.<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 logic<br />

must be stored in a variable called resultstring. For example, in the Northwind.dm1 sample model, the Data<br />

Dictionary lists a reusable trigger, SYSUPDATE, for the the Oracle platform. The code for this trigger includes<br />

the following statement, which is required for code to be generated for the trigger:<br />

resultstring = trigBody<br />

SQL page/tab<br />

Enter the SQL for the procedure.<br />

EMBARCAD<strong>ER</strong>O TECHNOLOGIES > <strong>ER</strong>/STUDIO® 8.0.3 US<strong>ER</strong> GUIDE 183

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

Saved successfully!

Ooh no, something went wrong!