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 • 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
- Page 131 and 132: USING ER/STUDIO > DEVELOPING THE LO
- Page 133 and 134: USING ER/STUDIO > DEVELOPING THE LO
- 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: 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 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
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