Sunteți pe pagina 1din 386

PHYSICAL DATA MODEL

User’s Guide
POWERDESIGNER 7
Copyright (c) 1988–1999 Sybase, Inc. All rights reserved.

Information in this manual may change without notice and does not represent a commitment on the part of Sybase, Inc. and its
subsidiaries.

The software described in this manual is provided by Sybase, Inc. under a Sybase License agreement. The software may be used
only in accordance with the terms of the agreement.

No part of this publication may be reproduced, transmitted, or translated in any form or by any means, electronic, mechanical,
manual, optical, or otherwise, without the prior written permission of Sybase, Inc. and its subsidiaries.

Sybase, SYBASE (logo), ADA Workbench, Adaptable Windowing Environment, Adaptive Component Architecture, Adaptive
Server, Adaptive Server Anywhere, Adaptive Server Enterprise, Adaptive Server Enterprise Monitor, Adaptive Server
Enterprise Replication, Adaptive Server Everywhere, Adaptive Server IQ, Adaptive Warehouse, AnswerBase, Anywhere
Studio, Application Manager, AppModeler, APT Workbench, APT-Build, APT-Edit, APT-Execute, APT-FORMS, APT-
Translator, APT-Library, ASEP, Backup Server, BayCam, Bit-Wise, Certified PowerBuilder Developer, Certified SYBASE
Professional, Certified SYBASE Professional Logo, ClearConnect, Client-Library, Client Services, CodeBank, Column Design,
ComponentPack, Connection Manager, CSP, Data Pipeline, Data Workbench, DataArchitect, Database Analyzer, DataExpress,
DataServer, DataWindow, DB-Library, dbQueue, Developers Workbench, Direct Connect Anywhere, DirectConnect,
Distribution Director, E-Anywhere, E-Whatever, Electronic Case Management, Embedded SQL, EMS, Enterprise Application
Server, Enterprise Application Studio, Enterprise Client/Server, Enterprise Connect, Enterprise Data Studio, Enterprise
Manager, Enterprise SQL Server Manager, Enterprise Work Architecture, Enterprise Work Designer, Enterprise Work
Modeler, EWA, First Impression, Formula One, Gateway Manager, GeoPoint, ImpactNow, InfoMaker, Information Anywhere,
Information Everywhere, InformationConnect, InstaHelp, Intellidex, InternetBuilder, iScript, Jaguar CTS, jConnect for JDBC,
KnowledgeBase, Logical Memory Manager, MainframeConnect, Maintenance Express, MAP, MDI Access Server, MDI
Database Gateway, media.splash, MetaWorks, MethodSet, MySupport, Net-Gateway, Net-Library, NetImpact, Next
Generation Learning, Next Generation Learning Studio, O DEVICE, OASiS, OASiS logo, ObjectConnect, ObjectCycle,
OmniConnect, OmniSQL Access Module, OmniSQL Toolkit, Open Client, Open ClientConnect, Open Client/Server, Open
Client/Server Interfaces, Open Gateway, Open Server, Open ServerConnect, Open Solutions, Optima++, Partnerships that
Work, PB-Gen, PC APT Execute, PC DB- Net, PC Net Library, Power++, Power Through Knowledge, power.stop,
PowerAMC, PowerBuilder, PowerBuilder Foundation Class Library, PowerDesigner, PowerDimensions, PowerDynamo,
PowerJ, PowerScript, PowerSite, PowerSocket, Powersoft, PowerStage, PowerStudio, PowerTips, Powersoft Portfolio,
Powersoft Professional, PowerWare Desktop, PowerWare Enterprise, ProcessAnalyst, RelationalBeans, Report Workbench,
Report-Execute, Replication Agent, Replication Driver, Replication Server, Replication Server Manager, Replication Toolkit,
Resource Manager, RW-DisplayLib, RW-Library, S Designor, S-Designor, SAFE, SAFE/PRO, SDF, Secure SQL Server,
Secure SQL Toolset, Security Guardian, SKILS, smart.partners, smart.parts, smart.script, SQL Advantage, SQL Anywhere,
SQL Anywhere Studio, SQL Code Checker, SQL Debug, SQL Edit, SQL Edit/TPU, SQL Everywhere, SQL Modeler, SQL
Remote, SQL Server, SQL Server Manager, SQL SMART, SQL Toolset, SQL Server/CFT, SQL Server/DBM, SQL Server
SNMP SubAgent, SQL Station, SQLJ, STEP, SupportNow, Sybase Central, Sybase Client/Server Interfaces, Sybase
Development Framework, Sybase Financial Server, Sybase Gateways, Sybase Learning Connection, Sybase MPP, Sybase SQL
Desktop, Sybase SQL Lifecycle, Sybase SQL Workgroup, Sybase Synergy Program, Sybase Virtual Server Architecture,
Sybase User Workbench, SybaseWare, Syber Financial, SyberAssist, SyBooks, System 10, System 11, System XI (logo),
SystemTools, Tabular Data Stream, The Enterprise Client/Server Company, The Extensible Software Platform, The Future Is
Wide Open, The Learning Connection, The Model For Client/Server Solutions, The Online Information Center, Transact-SQL,
Translation Toolkit, Turning Imagination Into Reality, UltraLite, UNIBOM, Unilib, Uninull, Unisep, Unistring, URK Runtime
Kit for UniCode, Viewer, Visual Components, VisualSpeller, VisualWriter, VQL, WarehouseArchitect, Warehouse Control
Center, Warehouse Studio, Warehouse WORKS, Watcom, Watcom SQL, Watcom SQL Server, Web Deployment Kit,
Web.PB, Web.SQL, WebSights, WebViewer, WorkGroup SQL Server, XA-Library, XA- Server and XP Server are trademarks
of Sybase, Inc. or its subsidiaries

Unicode and the Unicode Logo are registered trademarks of Unicode, Inc.

Other trademarks are the property of their respective owners.


Contents

About This Book ............................................................................................xi

1 Physical Data Model Basics ..............................................1


What is a PDM?........................................................................ 2
Objects in a PDM ...................................................................... 3
Defining a PDM......................................................................... 4
Opening an existing PDM................................................... 4
Creating a PDM .................................................................. 4
Detaching a PDM from the Workspace.............................. 6
Saving and closing a PDM ................................................. 6
Defining PDM options......................................................... 6
Modifying model properties ................................................ 9
Database properties ......................................................... 10
Creating a database ......................................................... 11
Package properties .......................................................... 12
Previewing SQL statements ............................................. 13
Using the PDM palette tool bar ............................................... 14
Selecting and releasing tools in the tool palette ............... 14

2 Using Business Rules......................................................15


What is a business rule?......................................................... 16
Defining business rules in a PDM ........................................... 17
Types of business rules.................................................... 17
Business rule properties ................................................... 17
Creating a business rule................................................... 18
Using business rules in a PDM ............................................... 20
Applying a business rule to the current object.................. 20
Attaching an expression to a business rule...................... 21

3 Building Physical Data Models........................................23


Defining tables ........................................................................ 24
Table properties ............................................................... 24
Creating a table ................................................................ 25
Modifying table properties ................................................ 27
Arranging items in a list attached to a table ..................... 29

iii
Naming a table constraint................................................. 30
Displaying text in table symbols ....................................... 31
Defining domains .................................................................... 35
Domain properties ............................................................ 35
Creating a domain ............................................................ 36
Indicating data type, length, and precision ....................... 37
Selecting a data type for a domain................................... 38
Selecting a data type from a list of standard data types... 40
Modifying domain properties ............................................ 43
Enforcing non-divergence from a domain ........................ 44
Using abstract data types ....................................................... 47
Types of abstract data types used in PowerDesigner ...... 47
How are abstract data types used in PowerDesigner? .... 48
Abstract data type properties ........................................... 49
Creating an abstract data type ......................................... 49
Linking an abstract data type to a Java class................... 51
Automatic linking to a Java class after reverse engineering55
Accessing a linked Java class in an OOM ....................... 55
Defining columns .................................................................... 58
Column properties ............................................................ 59
Creating a column ............................................................ 60
Selecting a data type for a column ................................... 61
Attaching a column to a domain ....................................... 63
Copying a column to another table................................... 65
Making a column mandatory or optional .......................... 66
Naming a column constraint............................................. 66
Configuring the display of the list of columns ................... 67
Defining keys .......................................................................... 69
Designating a primary key................................................ 70
Designating a foreign key................................................. 70
Adding parent table columns to a key .............................. 71
Auto-migrating foreign keys.............................................. 71
Designating an alternate key............................................ 73
Naming key constraints .................................................... 74
Defining references................................................................. 77
Reference properties........................................................ 78
Defining model options for references ............................. 79
Automatic reuse and migration of columns ...................... 80
Creating a reference......................................................... 82
Defining reference joins.................................................... 84
Changing a table at either end of a reference .................. 87
Sorting the list of references............................................. 88
Rebuilding references ...................................................... 89
Using referential integrity.................................................. 91
Referential integrity properties.......................................... 92
Defining referential integrity.............................................. 94

iv
Displaying text with reference symbols ............................ 96
Modifying a reference graphically..................................... 98
Defining indexes ................................................................... 100
Index properties.............................................................. 100
Creating an index ........................................................... 101
Removing a column from an index................................. 105
Rebuilding indexes ......................................................... 106
Deleting an index............................................................ 109
Defining views ....................................................................... 110
View properties............................................................... 110
Creating a view............................................................... 111
Modifying view properties ............................................... 114
Defining a query for a view ............................................. 115
Assigning an alias to a table or a column....................... 120
Inserting clauses in a query............................................ 121
Displaying query syntax.................................................. 125
Editing a query................................................................ 126
Displaying text in view symbols ...................................... 127
Defining check parameters ................................................... 129
Setting standard check parameters for objects.............. 129
Defining additional check parameters for objects .......... 131
Using a validation rule in check parameters................... 132
Managing quotation marks around values ..................... 134
Defining physical options ...................................................... 135

4 Managing Physical Data Models ...................................139


Managing users and owners................................................. 140
Creating a user ............................................................... 141
Attaching an object to a user .......................................... 141
Checking a PDM ................................................................... 143
Object parameters verified by Check model .................. 144
PDM check options ........................................................ 145
Object selection in the Check Model .............................. 146
Checking a global PDM .................................................. 147
Displaying previously applied check options .................. 149
Making corrections based on PDM check results .......... 150
Retrieving multidimensional objects...................................... 153
Importing an ERwin model into a PDM ................................. 154
Exporting a PowerDesigner 7 model to PowerDesigner 6.... 156

5 Reverse Engineering......................................................159
Reverse engineering a database schema ............................ 160
Generating a PDM from a database ..................................... 161
Filters and options for reverse engineering .................... 161
Reverse engineering database objects to a PDM .......... 162

v
Generating a PDM from a database creation script.............. 166

6 Triggers and Procedures............................................... 167


Trigger overview ................................................................... 168
How are triggers used in PowerDesigner?..................... 168
Using triggers........................................................................ 170
Trigger properties ........................................................... 170
Using variables in triggers .............................................. 171
Creating triggers automatically....................................... 171
Creating a trigger manually ............................................ 175
Modifying a trigger .......................................................... 177
Indicating trigger order ................................................... 180
Multiple triggers .............................................................. 180
Previewing a trigger........................................................ 182
Using trigger templates ......................................................... 183
Identifying PowerDesigner pre-defined trigger template types
....................................................................................... 184
Trigger template properties ............................................ 186
Using variables in trigger templates ............................... 187
Creating a trigger template............................................. 187
Modifying a trigger template ........................................... 195
Trigger naming conventions ........................................... 198
Changing trigger naming conventions............................ 198
Calling a related procedure in a trigger template ........... 199
Using template items ............................................................ 200
Identifying template items............................................... 202
Template item properties ............................................... 204
Using variables in template items................................... 204
Creating a template item ................................................ 205
Modifying a template item .............................................. 211
Declaring a template item in a trigger definition ............. 213
Defining stored procedures and functions ............................ 215
Defining templates for stored procedures and functions 215
Creating stored procedures and functions ..................... 216
Using macros........................................................................ 218
AKCOLN......................................................................... 218
ALLCOL.......................................................................... 218
DEFINE .......................................................................... 219
DEFINEIF ....................................................................... 220
ERROR .......................................................................... 220
FKCOLN......................................................................... 220
FOREACH_CHILD ......................................................... 221
FOREACH_COLUMN .................................................... 222
FOREACH_PARENT ..................................................... 223
INCOLN.......................................................................... 223
JOIN ............................................................................... 224
vi
NMFCOL ........................................................................ 225
PKCOLN......................................................................... 225
Generating triggers and procedures ..................................... 227
Trigger and procedure creation parameters................... 228
Generation script options ............................................... 228
Object selection parameters........................................... 230
Generating a trigger or procedure creation script........... 231
Creating triggers directly in a database .......................... 233
Creating and generating user-defined error messages.. 234

7 Database Creation and Modification.............................239


Using the ODBC interface..................................................... 240
Defining a data source ................................................... 241
Configuring a data source .............................................. 242
Connecting to a data source .......................................... 243
Displaying information about a connected database...... 244
Disconnecting from a data source.................................. 244
Accessing a database........................................................... 245
Changing target DBMS................................................... 245
Displaying data from a database .................................... 248
Executing SQL queries................................................... 249
Configuring tablespace and storage ..................................... 250
Sample tablespace and storage commands .................. 250
Defining tablespace and storage.................................... 251
Previewing tablespace and storage commands............. 253
Customizing scripts............................................................... 255
Inserting begin and end scripts for database creation.... 255
Inserting begin and end scripts for table creation........... 258
Formatting variables in customized scripts .................... 259
Generating a database ......................................................... 260
Creation parameters for tables, columns, and views ..... 260
Creation parameters for keys, indexes, and join indexes261
Database creation parameters ....................................... 263
Generation script options ............................................... 264
Object selection parameters........................................... 265
Selecting objects for generation ..................................... 266
Generating a database creation script ........................... 268
Creating a database directly........................................... 269
Archiving a PDM............................................................. 271
Modifying a database ............................................................ 272
Database generation synchronization parameters ......... 272
Database modification script options.............................. 273
Generating a modified database .................................... 273

vii
8 Generating a Conceptual Data Model from a Physical Data
Model .............................................................................. 281
Generating CDM objects ...................................................... 282
Translating PDM to CDM objects ................................... 282
Translating PDM to CDM data types .................................... 283
Translating physical data types ...................................... 283
Generating a CDM from a PDM............................................ 286
Generating and updating a CDM.................................... 286
CDM generation parameters and options ...................... 287
Object selection parameters .......................................... 288
Generating a new CDM from a PDM.............................. 288
Updating an existing CDM.............................................. 291
Generating and updating a PDM .......................................... 295
PDM generation parameters and options....................... 296

9 Generating an Object-Oriented Model from a Physical Data


Model .............................................................................. 299
Generating OOM Objects ..................................................... 300
Translating PDM to OOM objects .................................. 300
Translating PDM to OOM data types .................................... 301
Translating object language data types.......................... 301
Generating an OOM from a PDM ......................................... 302
Generating and updating an OOM ................................. 302
OOM generation options ................................................ 303
Object selection parameters .......................................... 304
Generating a new OOM from a PDM ............................. 304
Updating an existing OOM ............................................. 307

10 DBMS Definition Editor.................................................. 311


Using the DBMS Definition Editor ......................................... 312
DBMS Overview ............................................................. 312
The DBMS Editor ........................................................... 312
DBMS categories ........................................................... 313
Viewing DBMS fields ...................................................... 313
Using the List of DBMS .................................................. 316
Creating a new DBMS .................................................... 316
Importing a DBMS or a PowerDesigner DEF file ........... 318
Saving a DBMS .............................................................. 318
Modifying a DBMS.......................................................... 319
Consulting trigger templates and template items ........... 322
Defining constraint name templates............................... 322
Formatting variables in a DBMS..................................... 326
Defining data type translations ....................................... 328
Defining reserved keywords ........................................... 329

viii
Defining default physical options in a DBMS.................. 331
Defining physical options in a DBMS.............................. 332

Appendix Variables in PowerDesigner ..........................................339


List of PowerDesigner variables ........................................... 340
List of PowerDesigner formatting variables .......................... 351

Glossary .........................................................................................353

Index .........................................................................................357

ix
x
About This Book

Subject This book describes the PowerDesigner Physical Data Model data modeling
environment. It shows you how to do the following:
♦ Build a Physical Data Model (PDM)
♦ Create and use business rules and other model objects
♦ Generate triggers, procedures, scripts, and databases
♦ Reverse engineer existing databases
♦ Generate a Conceptual Data Model and an Object-Oriented data Model
from a PDM

Audience This book is for anyone who will be building data models with
PowerDesigner. Although it does not assume you have knowledge about any
particular topic, having some familiarity with relational databases, SQL, and
design methodology is helpful.

Where to find This book focuses on the design and construction of a Physical Data Model.
information General information about the PowerDesigner modeling environment, for
example using many of the graphic tools, interface features, merging models,
and using the Browser, can be found in the PowerDesigner General Features
Guide.

To help you do your work more easily, this book is divided into chapters that
focus on particular goals.

If you want to Use these parts of the book


Learn about the environment Physical data Model Basics
Build a Physical Data Model Building a Physical Data Model
Use model management Managing Physical Data Models
functions, for example
verifying the model, managing
users, and importing an Erwin
model

xi
About This Book

If you want to Use these parts of the book


Using and generating triggers Triggers and Procedures
and procedures
Generate a database Database Creation and Modification
Generate a Conceptual Data The chapters on generating conceptual data
Model or an Object Oriented- models and object-orientated models
Model from a PDM
Current reference material Appendix

xii
C H A P T E R 1

Physical Data Model Basics

About this chapter This chapter presents the Physical Data Model (PDM) and explains the role
of physical modeling in the design process.
Contents
Topic Page

What is a PDM? 2
Objects in a PDM 3
Defining a PDM 4
Using the PDM palette tool bar 14

1
What is a PDM?

What is a PDM?
The PDM specifies the physical implementation of the database.
With the PDM, you consider the details of actual physical implementation. It
takes into account both software or data storage structures. You can modify
the PDM to suit your performance or physical constraints.
PDM roles The PDM fills the following roles:
♦ Represent the physical organization of data in a graphic format
♦ Generate database creation and modification scripts
♦ Define referential integrity triggers and constraints
♦ Reverse engineer existing databases

PDM creation There are several ways to create a PDM:


♦ Create a PDM from scratch
♦ Reverse engineer a database into a PDM
♦ Generate a PDM from Conceptual Data Model (CDM)
♦ Generate a PDM from an Object-Oriented Model (OOM)

2
Chapter 1 Physical Data Model Basics

Objects in a PDM
A PDM represents the interaction of the following objects:

Object Description
Table Collection of rows (records) that have associated columns (fields)
Column Data structure that contains an individual data item within a row
(record), model equivalent of a database field.
Key Column or columns whose values uniquely identify each row in a
table. A key can be designated as a primary or alternate key
Primary key Column or columns whose values uniquely identify each row in a
table, and are designated as the primary identifier of each row in
the table
Alternate key Column or columns whose values uniquely identify each row in a
table, and which is not a primary key
Foreign key Column or columns whose values depend on and migrate from a
primary or alternate key in another table.
Index Data structure associated with one or more columns in a table, in
which the column values are ordered in such a way as to speed up
access to data
Reference Link between a primary or an alternate key in a parent table, and
a foreign key of a child table. Depending on its selected
properties, a reference can also link columns that are independent
of primary or alternate key columns
View Data structure that results from a SQL query and that is built from
data in one or more tables

3
Defining a PDM

Defining a PDM
You can open existing PDM, or create a new PDM. You can also set options
to define how your model is modified, and the type of information that it
displays.

Opening an existing PDM

v To open an existing PDM:


1 Select File➤Open.
A standard open file dialog box appears.
2 Select or browse to the directory that contains the PDM to open.

Showing all PowerDesigner files


You can make visible all files that are supported by PowerDesigner
by selecting All PowerDesigner Files from the Type dropdown
listbox.

3 Select a PDM file.


4 Click the Open button.
The PDM is displayed in the diagram window. The PDM appears as a
model node under the Workspace node in the Browser.

Creating a PDM
When you create a new PDM you must choose a current DBMS. All of the
objects that you create in a PDM conform to the SQL specifications of the
current DBMS.
DBMS library In PowerDesigner the current DBMS is a text file in XML format that
contains all the SQL syntax and specifications for an actual Database
Management System.
PowerDesigner has a DBMS definition for each supported database. These
DBMS definition files are stored in the DBMS Library directory in the
PowerDesigner path. Each DBMS definition file has the extension .XDB
which signifies XML Database File.

4
Chapter 1 Physical Data Model Basics

When you create a PDM you can choose to connect to a DBMS in one of the
following ways:

DBMS Description
Link Current DBMS for the PDM refers to the DBMS definition
file stored in the DBMS library. Any modifications made to
the DBMS are available to the linked PDM
Local to the model Current DBMS for the PDM is a copy of the DBMS
definition file stored in the DBMS library. The current
DBMS is independent of the original DBMS definition file
so any modifications made in the DBMS definition file in
the DBMS library are not available to the PDM. The
DBMS is saved with the PDM and can not be used
externally of it

v To create a new PDM:


1 Select File➤New.
A selection box appears. It lists the available PowerDesigner modules.
2 Click Physical Data Model in the list and click OK.
The Choose DBMS dialog box appears.

3 Select a current DBMS from the DBMS dropdown listbox.


or
Click the Browse button at the end of the DBMS dropdown listbox and
browse to the directory that contains the .XML file for the current
DBMS.
Select the .XML file and click the Open button.
4 The name for the current DBMS appears in the DBMS box.
5 Select the Link radio button
or
Select the Local to the Model radio button.
6 Click OK.

5
Defining a PDM

A new PDM opens in the current Workspace. An empty diagram


window appears containing a palette of design tools. The new PDM node
appears under the Workspace node in the Browser.

Detaching a PDM from the Workspace


You can detach a PDM from a workspace. When a PDM is detached from a
Workspace its node is removed from the Browser and it is no longer defined
in the Workspace, but the file is not deleted from your operating
environment.

v To detach a PDM from a Workspace:


1 Right-click the PDM node in the Browser and select Detach from the
context menu.
A confirmation box asks if you want to save the PDM.
2 Click Yes if you want to save modifications to the PDM.
Select or browse to a directory.
Type a name for the file and click the Save button.
or
Click No if you don’t want to save modifications to the file.
The PDM is removed from the Workspace.

Saving and closing a PDM


You save a PDM by selecting File➤Save.
You close a PDM by selecting File➤Close.

Defining PDM options


You can set options that apply to a PDM for the following objects:
♦ Columns and domains
♦ References
♦ Default data type

Columns and From the Model Options dialog box, you can choose to enforce non-
Domains divergence between a domain definition and the columns using the domain,
for the following column properties:

6
Chapter 1 Physical Data Model Basics

Property Columns in the domain cannot have divergent


Data type Data type, length, and precision
Check Check parameters
Rules Business rules
Mandatory Mandatory or optional property

Your choice of whether or not to enforce domain and column non-divergence


has the following results:

Non-divergence Result
Not enforced Columns that are divergent from the domain definition can
remain attached to the domain
Enforced Columns that are divergent from the domain (for certain
column properties) must be detached from the domain

If you modify domain non-divergence options, these changes apply only to


the current PDM.
Updating column You can select the column properties that you want to be updated for all
properties column using a domain, when that domain is modified.
Your selection to enforce, or not to enforce, non-divergence between a
domain and the columns using the domain definition, has the following
results:

Non-divergence Property is… Result when domain is modified


Enforced Selected Property is updated for all data items
using domain
Not selected No property is updated
Not enforced Selected You must confirm property update for all
columns using domain
Not selected No property is updated

Column property When you choose to enforce non-divergence for a column property, each
can not be instance of that column property in the List of Columns and the Columns
modified page for the table property sheet, appears grayed and can not be modified.
If you want to modify a column property that is defined as non-divergent, you
must detach the column from its domain, or clear the Enforce non-divergence
checkbox in Model Options.

7
Defining a PDM

Enforce non- You can also clear the Enforce Non-divergence checkbox and select one or
divergence not more of the column properties listed below the checkbox.
selected
When you modify a column property and it diverges from the domain
definition that it is using, you are asked if you want to keep a modification
and diverge from the domain.
If you modify PDM model options, these options apply only to the current
PDM.
$ For information on other model options, see the PowerDesigner
Features Guide.
Reference You can select the following model options for references in your PDM:

Option When selected…


Unique code Requires that references have unique codes
Auto-reuse columns An existing column in child table is used as the matching
foreign key column when both of the following
conditions apply:
♦ Child column has same code as migrating primary key
column
♦ Child column is not already a foreign key column
Auto-migrate Primary key columns are automatically migrated to a
columns child table as foreign key columns at reference creation.
You can also choose to migrate any of the following
column properties
Domain
Check (Check parameters)
Rules (Business rules)
*Domain migration Domain automatically migrated with Foreign key
*Check migration Check parameter automatically migrated with Foreign key
*Rules migration Business rule automatically migrated with Foreign key
Default link on Reference links Primary key columns to foreign key
creation: Primary key columns at creation
Default link on Reference not linked. No joins are created.
creation: User-
defined

* Only available when Auto-migrate FK is selected.

8
Chapter 1 Physical Data Model Basics

$ For more information on the options Auto-reuse and Auto-migrate, see


the section Automatic reuse and migration of columns in the chapter Building
Physical Data Models.
Default data type The default data type is the data type that applies to columns and domains if
no data type is selected.

v To define PDM options:


1 Select Tools➤Model Options.
or
Right-click the diagram background and select Model Options from the
contextual menu
The Model Options dialog box opens to the Model page.

2 Select or clear PDM options.


3 Click OK.

Modifying model properties


The Model property sheet displays the definition of the current model. From
this property sheet you can modify the model definition.
A PDM has the following model properties:

9
Defining a PDM

Property Description Length


Name Name for the model 254
Code Code for the model This code is generated 254
in database scripts
Comment Descriptive label for the model 32Kb
DBMS Current DBMS for the model. You can —
open the property sheet for the DBMS by
clicking the Properties tool at the end of
the box
Database Database name —

v To modify the model properties:


1 Select Model➤Model Properties.
or
Right click the diagram background and select Properties from the
contextual menu.
The model property sheet appears.
2 Type changes to model properties.
3 Click OK.

Database properties
You can define a database for a PDM.
$ For more information on creating a database, see the section Creating a
database.
A database definition includes the following properties

Property Description Length


Name Name for the database 254
Code Code for the database. This code is generated in 254
database scripts
Comment Descriptive label for the database 32Kb
DBMS DBMS for the database —
Options Physical options available in the DBMS —

10
Chapter 1 Physical Data Model Basics

Property Description Length


Script Before and end scripts that are inserted at the start —
and end of a database creation script
Rules Business rules for the database —

Creating a database
You create a database for the model from the model property sheet.

v To create a database:
1 Select Model➤Model Properties.
The model properties sheet appears.
2 Click the Create tool at the end of the Database box.

A default database name is entered in the database box.


3 Click the Properties tool at the end of the Database box.

A confirmation box appears asking you to commit the creation of the


database.
4 Click Yes.

11
Defining a PDM

The database property sheet appears.

5 Type a name and code for the database.


6 Type a description in the Comment box.
7 Click the Options tab.
The Options page appears. It lists the physical options available for the
DBMS.
8 Select and enter values for database options.
$ For more information on defining physical options, see the section
Defining physical options in the chapter Building Physical Data Models.
9 Select other property tabs and enter appropriate database properties.
10 Click OK in each of the dialog boxes.

Package properties
A package is a piece of a model.
When working with a large model, you can split the model into smaller
subdivisions to avoid manipulating the entire set of model objects. Packages
can be useful to assign portions of a model, representing different tasks and
subject areas, to different development teams.

12
Chapter 1 Physical Data Model Basics

You can create as many packages as you need in a model. The name of each
package must be unique in the model.
Packages have properties displayed on property sheets. All packages share
the following common properties:

Property Description Length


Name Names are like titles that clearly identify the package 254
during the design process
Code Codes are references for packages 254
Comment A comment is an optional label that describes a 32Kb
package and provides more information than the name
Namespace Option that defines the package as being the area in -
which the name of an object must be unique in order to
be used.

$ For more information on packages, see the PowerDesigner General


Features Guide.

Previewing SQL statements


A preview of the SQL script that will be generated is shown on the Preview
page, which is accessible from the property sheet for the following objects:
♦ Tables
♦ Indexes
♦ Views
♦ References
♦ Keys
The text in the script preview is color coded as follows

Text color Represents


Blue SQL reserved word
Black Statement body
Red Variable
Green Comment

13
Using the PDM palette tool bar

Using the PDM palette tool bar


The palette is a tool bar that can be docked anywhere in the workspace. The
tools in the PDM Palette enact all major functions needed to build and
modify a PDM.

The majority of the tools in the Palette are common to all PowerDesigner
modules and are described in the PowerDesigner General Features Guide.
The following table indicates the names and functions of each tool that is
specific to the PDM in the Palette:
PDM object tools Tool Name Action
Table Insert table symbol

Reference Insert reference symbol

View Insert view symbol

Selecting and releasing tools in the tool palette

v To select a tool in the Palette:


♦ Click the tool

v To release a tool in the Palette:


♦ Right-click anywhere in the diagram outside the tool palette.
The Pointer tool is selected by default.

14
C H A P T E R 2

Using Business Rules

About this chapter This chapter describes how business rules help you model information.
Contents
Topic Page

What is a business rule? 16


Defining business rules in a PDM 17
Using business rules in a PDM 20

15
What is a business rule?

What is a business rule?


A business rule is a rule that your business follows. A business rule could be
a government-imposed law, a customer requirement, or an internal guideline.
Starts as an Business rules often start as simple observations, for example "customers call
observation toll-free numbers to place orders." During the design process they develop
into more detailed expressions, for example what information a customer
supplies when placing an order or how much a customer can spend based on
a credit limit.
Guides modeling Business rules guide and document the creation of a model. For example, the
rule "an employee belongs to only one division" can help you graphically
build the link between an employee and a division.
Complements Business rules complement model graphics with information that is not easily
graphics represented graphically. For example, some rules specify physical concerns
in the form of formulas and validation rules. These technical expressions do
not have a graphical representation.
CDM to PDM During generation of a PDM from a CDM, the business rules transfer directly
generation into the PDM. In the PDM, you further specify business rules to suit physical
concerns.
Check parameters You can attach business rules to objects in a PDM. You can generate
business validation rules as check parameters if the validation rules are
attached to columns or domains.
$ For more information on defining and using check parameters, see the
chapter "Building a Physical Data Model".

16
Chapter 2 Using Business Rules

Defining business rules in a PDM


You can define a business rule which can be attached to an object in the
PDM.

Types of business rules


In PowerDesigner, you can define several different types of business rules.
Only the validation rule type can be generated to a database.
Types of business The different business rule types that you can define in a PDM are described
rules below:

Rule type Describes Example


Definition Characteristics or properties of A customer is a person identified
an object in the information by a name and an address
system
Fact Certainty or existence in the A client may place one or more
information system orders
Formula Calculation employed in the The total order is the sum of all
information system the order line costs
Validation Constraint on a value in the The sum of the order totals for a
information system given client must not be greater
than that client’s allowance

Business rule properties


A business rule definition includes the following properties:

17
Defining business rules in a PDM

Property Description Maximum


length
Name Name for the rule 254
Code Reference name for the rule 254
Comment Descriptive label for the rule 32Kb
Type Indicates whether the rule is a definition, a fact, a —
formula, or a validation
Expression Presence of associated expression —
Notes Presence of associated notes —

Creating a business rule


Before you create business rules, formulate your rules by asking yourself the
following questions:
♦ What business problems do I want to address?
♦ Are there any procedures that my system must respect?
♦ Do any specifications dictate the scope of my project?
♦ Do any constraints limit my options?
♦ How do I describe each of these procedures, specifications, and
constraints?
♦ How do I classify these descriptions: as definitions, facts, formulas, or
validation rules?

18
Chapter 2 Using Business Rules

v To create a business rule:


1 Select Model➤Business Rules.
The List of Rules appears. It displays the business rules defined for the
model.

2 Click a blank line in the list.


or
Click the Add a Row tool.
An arrow appears at the beginning of the line.
3 Type a name and a code for the business rule.
4 Click Apply.
The creation of the new business rule is committed.
5 Click the new business rule line.
An arrow appears at the beginning of the line.
6 Click the Properties tool.
or
Double click the arrow at the beginning of the line.
The property sheet for the new business rule appears.
7 Select a business rule type from the Type dropdown listbox
8 Click OK.

19
Using business rules in a PDM

Using business rules in a PDM


You can attach a business rule to an object in the PDM. You can create a
server expression for a business rule which can be generated to a database. A
business rule expression can also be inserted in a trigger or stored procedure.

Applying a business rule to the current object


You can apply a business rule to the current object from its property sheet.

v To apply a business rule to the current object:


1 Double-click an object in the diagram.
The object property sheet appears.
2 Click the Rules tab.
The Rules page appears. It displays business rules attached to the object.

3 Click the Add Rules tool.


A list of business rules appears.
4 Select one or more business rules.
5 Click OK in each of the dialog boxes.

20
Chapter 2 Using Business Rules

Attaching an expression to a business rule


A business rule typically starts out as a description. As you develop your
model and analyze your business problem, you can complete a rule by adding
a technical expression. The syntax of expressions depends on the target
database.
Each business rule can include two types of expression:
♦ Server
♦ Client
Only the server expression can be generated to a database. You can generate
server expressions as check parameters if they are attached to tables,
domains, or columns.
A client expression is used mainly for documentation purposes. However,
you can insert both types of expression into a trigger or a stored procedure.

v To attach an expression to a business rule:


1 Select Model➤Business Rules.
The List of Business Rules appears.
2 Click a business rule.
An arrow appears at the beginning of the line.
3 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.
The Business rule property sheet appears.
4 Click the Expression tab.
The Expression page appears.
5 Click the Server tab at the bottom of the page to define a server
expression.
or
Click the Client tab at the bottom of the page to define a client
expression.
6 Type an expression in the Expression textbox.
7 Click OK in each of the dialog boxes.

21
Using business rules in a PDM

22
C H A P T E R 3

Building Physical Data Models

About this chapter This chapter describes how to build a Physical Data Model (PDM). It
explains the role of each object in a PDM. It also shows how to modify PDM
objects.
Contents
Topic Page

Defining tables 24
Defining domains 35
Using abstract data types 47
Defining columns 58
Defining keys 69
Defining references 77
Defining indexes 100
Defining views 110
Defining check parameters 129
Defining physical options 135

23
Defining tables

Defining tables
A table represents a collection of data arranged in columns and rows. It is the
model equivalent of a database table.

Table properties
A table definition includes the following properties:

Maximum
Property Description length
Name Name for the table. This name improves the 254
readability of the model
Code Reference Code for the table. This code is 254
generated in database scripts
Comment Descriptive label for the table 32K
Owner Name of table owner. You choose an owner from 254
a list of users. A table can only have one owner at
a time. This is normally the table creator
Number Estimated number of occurrences in the physical —
database for the table (the number of records).
This number is used to compute database size
Generate Indicates to generate the table in the database —
Type Table can be of type Dimension or Fact —
Check Table constraint that enforces data requirements —
of check parameters.
Script Begin and end scripts for table creation —
Preview SQL code for table —
Options Physical options for the table. These are DBMS —
specific
Version Table owner, version number, modification and
Information creation details
Notes Description associated with table

24
Chapter 3 Building Physical Data Models

A table definition also includes the following properties, each with their own
respective property sheet that can be accessed independently of the table.
♦ Columns
♦ Indexes
♦ Keys
♦ Triggers
♦ Business rules

Creating a table
There are three approaches to creating a table.
♦ Insert a table symbol directly in the diagram
♦ Add a new table to the list of tables
♦ Insert a table symbol in the diagram from the Browser
In each approach you must assign a name and a code to the table.

Creating a table by inserting a symbol in the diagram

v To create a table by inserting a symbol in the diagram:


1 Click the Table tool.
2 Click an empty space in the diagram.
The following symbol appears at the click position:

At creation, a table is named Table_n, where n is a number assigned in


the order of the creation of objects.
3 Click the Pointer tool.
4 Double-click the new table symbol in the diagram.
The table property sheet appears.
5 Type a table name and a table code.
6 Click OK.

25
Defining tables

Creating a table by inserting it in the list

v To create a table by inserting it in the list:


1 Select Model➤Tables.
The list of available tables appears.

2 Click a blank line in the list.


or
Click the Add a Row tool.
An arrow appears at the beginning of the line and a default table name is
listed.
3 Type a table name and a table code.
4 Click OK.
A symbol for this table is inserted in the current diagram.

Creating a table from the Browser

v To create a table from the Browser:


1 From the browser, right click the node for your model.
A contextual menu appears.
2 Select New➤Table.
The symbol for this table is inserted in the current diagram, and a new
table node is added to the tree view in the Browser.

26
Chapter 3 Building Physical Data Models

3 Double-click the new table symbol in the diagram


The table property sheet appears.
4 Type a table name and a table code.
5 Click OK.

Modifying table properties


There are two approaches to modifying table properties:
♦ Modify a table property sheet
♦ Modify an entry in the list of tables

Modifying table properties from the property sheet


The Table property sheet displays table definitions which you can modify.

v To modify table properties from its property sheet:


1 Double-click a table in the model.
The table property sheet appears.

27
Defining tables

2 Type changes to table properties


or
Click on a page tab.
Type or select table properties as required.
3 Click OK.

Modifying table properties from the list


The list of tables includes all tables attached to the current model. You can
modify certain table properties from the list.

v To modify table properties from the list:


1 Select Model➤Tables.
The List of Tables appears.

2 Click the table that you want to modify.


An arrow appears at the beginning of the line.
3 Modify the name or the code directly in the list.
4 Select the G checkbox to generate the table.
Clear the G checkbox to not generate the table.
5 Click OK.
or
Click a different table in the list.

28
Chapter 3 Building Physical Data Models

List of tables for packages


If you are working on a package, the list of tables only displays tables
defined in that package.

Arranging items in a list attached to a table


Each table has it own list for each of the following table properties:
♦ Columns
♦ Indexes
♦ Keys
♦ Triggers
♦ Business rules
Each list is specific to a particular table. You can arrange the list items in any
order. This order becomes the order of generation in a database.
The following buttons change the position of selected items in the list.

Button Moves selected items to


Top of list

Up one page

Up one line

Down one line

Down one page

Bottom of list

v To arrange items in a list attached to a table:


1 Double-click a table symbol.
The table property sheet appears.
2 Click a tab for a table property.

29
Defining tables

The property page appears listing all instances of the property for that
table.
3 Select one or more items in the list.
4 Use the arrow buttons to move the items in the list.
5 Click OK.

Naming a table constraint


A table constraint is a named check that enforces data requirements of check
parameters.
Whenever you place a data restriction on a table, a constraint is created
automatically. You have the option of specifying a name for the constraint. If
you choose not to specify a name for the constraint, the database creates a
default constraint name for you automatically.
This name helps you to identify and customize a table constraint in scripts for
database creation and modification.

v To name a table constraint:


1 Double-click a table in the model.
The table property sheet appears.
2 Click the Check tab.
The Check page appears listing all check parameters defined for the
table.
3 Click the User Defined button at the end of the Constraint Name box.
4 Type changes to the constraint name in the Constraint Name box.

Undo changes to a constraint name


You can always return to the default constraint name by re-clicking
the User-Defined button.

5 Click OK.

30
Chapter 3 Building Physical Data Models

Displaying text in table symbols


You can display the following text in a table symbol:
Table display Text display When selected, what it displays
preference
Columns All columns, primary key columns, or a defined number (limit) of
columns depending on the selections listed below*
*All columns All table columns
*PK columns Primary key columns only
*Limit (x) Number of columns depending on defined value of x
Indexes All indexes defined for table columns
Keys All keys defined on table
Triggers All triggers defined for table
Owner Name of table owner

31
Defining tables

Table Columns You can display information about columns in each table.
display
Keys and indexes are represented by indicators in the table symbol. Each key
and index indicator is assigned a number. You can use these numbers to keep
track of the different groups of alternate keys, foreign keys, and indexes in
your model.
You can display the following column information in a table symbol:

Text display When selected, what it displays


preference Example
Data types Data type for each column

Replace by Domain codes for each column


domains attached to a domain

Key <pk>, <fk>, and <ak> indicators next


Indicators to primary key, foreign key, and
alternate key columns respectively.
When the Keys preference is also
selected, the key names are listed at
the bottom of the table symbol

Index <i(number)> indicator next to


indicators indexed columns. When the Indexes
preference is also selected, the index
names and corresponding numbers
are listed at the bottom of the table
symbol

NULL/NOT Column indicator: null, not null,


NULL identity, or with default (DBMS-
dependent)

32
Chapter 3 Building Physical Data Models

Foreign key indicator numbers


Foreign key numbers can be displayed next to their corresponding foreign
key names on the references links between the appropriate parent and
child tables.

$ For information on displaying text with a reference symbol, see the


section Displaying text with reference symbols.

v To display text in a table symbol:


1 Select Tools➤Display preferences.
or
Right-click the diagram background and select Display Preferences from
the context menu.
The Display Preferences dialog box opens to the General page.
2 Select Table under the Object View node in the Category tree view.
The Table page appears.

3 Select or clear checkboxes in the Table groupbox and Table Columns


groupbox.

33
Defining tables

Default options
Click the Default button to display default table display preferences.
Click the Set As Default button to set current display preferences as
default selections.

4 Click OK.

34
Chapter 3 Building Physical Data Models

Defining domains
Domains help you identify the types of information in your project. They
define the set of values for which a column is valid. Applying domains to
columns makes it easier to standardize data characteristics for columns in
different tables.
In a PDM, you can associate the following information with a domain:
♦ Data type, length, and precision
♦ Check parameters
♦ Business rules
♦ Mandatory property

Domain properties
Each domain definition includes the following properties:

Property Description Maximum


length
Name Name for the domain 254
Code Reference name for the domain 254
Comment Descriptive label for the domain 32Kb
Data type Form of the data corresponding to the domain, —
such as numeric, alphanumeric, Boolean, or
others
Length Maximum number of characters —
Precision Number of places after the decimal point, for data —
values that can take a decimal point
Mandatory Domain values are mandatory for all columns —
using that domain
Identity (For Sybase System 10, Sybase System 11, and —
MS SQL Server 6 only). When selected, indicates
that the data is auto-incremented for columns
using that domain
With default (For Ingres, DB2, SQLBase, Xdb, Datacom, and —
OpenIngres only) When selected, indicates if a
default value is assigned to a column using the
domain, when a Null value is inserted

35
Defining domains

A domain definition can also include the following properties, which have
associated values or information used by columns attached to the domain:

Property Description
Standard checks Check parameters defined for the domain
Additional checks Domain constraints or validation rules not defined by
standard check parameters
Rules Business rules attached to the domain

Creating a domain

You create a domain from the list of domains.

Accessing the List of Domains


You can access the List of Domains from the current model, or by right
clicking the appropriate model node in the Browser, and selecting
New➤Domain from the contextual menu.

v To create a domain:
1 Select Model➤Domains.
The list of available domains appears.
2 Click a blank line in the list.
or
Click the Add a Row tool.
An arrow appears at the beginning of the line.
3 Type a domain name and a domain code.
4 Click Apply.
The creation of the new domain is committed.
5 Click the new domain line.
An arrow appears at the beginning of the line.
6 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.

36
Chapter 3 Building Physical Data Models

The property sheet for the new domain appears.

7 Select a data type.


Specify length and precision as required.
Select or clear the Mandatory, Identity, and With Default checkboxes.
$ For information on data types and selecting a data type for a
domain see the following sections Indicating data type, length, and
precision, and Selecting a data type for a domain.
8 Click on a page tab.
Type or select domain properties as required.
9 Click OK
You return to the List of Domains.
10 Click OK.
or
Click another domain line.

Indicating data type, length, and precision


The data types that you can select in a PDM depend on your current DBMS.
Length and The properties length and precision do not apply to all data types. Depending
precision on data type, length may indicate a maximum or a fixed number of
characters.

37
Defining domains

In the list of available data types, a variable indicates where you have to type
a length or precision, as follows:

Variable Replace with


%n Length
%s Length with precision
%p Decimal precision

For example, if you are using Sybase Adaptive Server Anywhere and you
choose the data type char(%n), you can choose a length of ten by typing
char(10).

Undefined data All target DBMS allow you to select the <undefined> data type. The
type <undefined> data type indicates which domains remain without data types. If
an <undefined> data type is present when you generate your database, it is
replaced by the default data type for your database.

Selecting a data type for a domain

You can select a data type for a domain in two ways:


♦ Directly from the List of Domains
♦ From the property sheet for the domain

The list of standard When you select a data type for a domain from its property sheet, you can
data types choose a data type from a list of standard data types available in
PowerDesigner. This list presents the available data types in a more
structured and complete format than the abbreviated format used in the data
type dropdown listbox in the list of domains.

Selecting a data type for a domain from the list

v To select a data type for a domain from the list:


1 Select Model➤Domains.
The list of domains appears.
2 Click the domain that you want to define.
An arrow appears at the beginning of the line.
3 Click the Data Type column.

38
Chapter 3 Building Physical Data Models

A dropdown listbox appears.


4 Select a data type from the dropdown listbox.

Undefined data type


If you do not want to select a data type immediately, you can choose
the <Undefined> data type. When you generate the database, this data
type is replaced by the default data type for your target DBMS.

5 Click OK.

Selecting a data type for a domain from its property sheet

v To select a data type for a domain from its property sheet:


1 Select Model➤Domains.
The List of Domains appears.
2 Click the domain to define.
An arrow appears at the beginning of the line.
3 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.
The domain property sheet appears.
4 Select a data type from the Data Type dropdown list box.

Selecting a data type from a list of standard data types


You can select a data type from a list of standard data types by
clicking the Question Mark button at the end of the Data Type
dropdown listbox, and selecting the radio button for a data type from
the list that appears.

5 Type the maximum number of characters for the data item in the Length
box.
6 If the data type can include values that take a decimal point, type the
number of places after the decimal point in the Precision box.
7 Click OK.
The change of data type appears in the list of domains.

39
Defining domains

Undefined data type


If you do not want to select a data type immediately, you can choose
the <Undefined> data type. When you generate the database, this data
type is replaced by the default data type for your target DBMS.

Selecting a data type from a list of standard data types


You can select a data type from a list of standard data types. This is the same
list that is available in the Conceptual Data Model. PowerDesigner
automatically maps the standard data type to a physical data type.
The length and precision are properties that do not apply to all data types.
Furthermore, depending on data type, length may indicate a maximum or a
fixed number of characters.
The tables below indicates the data types for which you can specify:
♦ Fixed length
♦ Maximum length
♦ Decimal precision

Numeric data types Conceptual data type What it stores Length? Precision?
Integer 32-bit integer — —
Short Integer 16-bit integer — —
Long Integer 32-bit integer — —
Byte 256 values — —
Number Numbers with a fixed Fixed á
decimal point
Decimal Numbers with a fixed Fixed á
decimal point
Float 32-bit floating decimal Fixed —
numbers
Short Float Less than 32-bit floating — —
decimal number
Long Float 64-bit floating decimal — —
numbers
Money Numbers with a fixed Fixed á
decimal point

40
Chapter 3 Building Physical Data Models

Conceptual data type What it stores Length? Precision?


Serial Automatically Fixed —
incremented numbers
Boolean Two opposing values — —
(true/false; yes/no; 1/0)

Character data Conceptual data type What it stores Length?


types
Characters Character strings Fixed
Variable Characters Character strings Maximum
Long Characters Character strings Maximum
Long Var Characters Character strings Maximum
Text Character strings Maximum
Multibyte Multibyte character strings Fixed
Variable Multibyte Multibyte character strings Maximum

Time data types Conceptual data type What it stores


Date Day, month, year
Time Hour, minute, and second
Date & Time Date and time
Timestamp System date and time

Other data types Conceptual data type What it stores Length?


Binary Binary strings Maximum
Long Binary Binary strings Maximum
Image Images Maximum
Bitmap Images in bitmap format (BMP) Maximum
OLE OLE links Maximum
Other User-defined data type —
Undefined Not yet defined data type —

v To select a data type from a list of standard data types:


1 Select Model➤Domains.

41
Defining domains

The List of Domains appears.


2 Click the domain to define.
An arrow appears at the beginning of the line.
3 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.
The domain property sheet appears.
4 Click the Question Mark button next to the Data Type dropdown listbox.

Selecting from the Data Type dropdown listbox


You can also select a data type directly from the Data Type dropdown
listbox.

A list of standard data types appears.

5 Click the radio button corresponding to the data type you want to apply.
The code for the data type appears in the Code box.

Undefined data type


If you do not want to select a data type immediately, you can choose
the Undefined data type.

42
Chapter 3 Building Physical Data Models

6 Type the maximum number of characters for the data type in the Length
box.
7 If the data type can include values that take a decimal point, type the
number of places after the decimal point in the Precision box.
8 Click OK.
The change of data type appears in the Data Type box.

Modifying domain properties


You can modify domain properties from its property sheet.
When you modify a domain, you can choose to automatically update the
following properties for columns using the domain:
♦ Data type
♦ Check parameters
♦ Business rules
♦ Mandatory values

v To modify domain properties:


1 Select Model➤Domains.
The List of Domains appears.
2 Click a domain from the list.
An arrow appears at the start of the line.
3 Click the Properties tool.
or
Double-click the arrow at the start of the line.

Accessing a property sheet from the Browser


You can also access a domain property sheet by double-clicking the
appropriate domain node in the Browser.

The Domain property sheet appears.


4 Type changes to domain properties.
or
Click on a page tab.
Type or select domain properties as required.

43
Defining domains

5 Click OK.
If the domain is used by one or more columns, an update confirmation
box appears asking if you want to modify domain properties for the
columns using the domain.
If the domain is not used by any columns, then you do not receive the
update confirmation box.
6 Select the properties that you want to be updated for all columns using
the domain.
7 Click Yes.

Enforcing non-divergence from a domain


From the Model Options dialog box, you can choose to enforce non-
divergence between a domain and the columns that use the domain.
Your choice of whether or not to enforce domain and column non-divergence
has the following results:

Non-divergence Result
Not enforced Columns that are divergent from the domain definition can
remain attached to the domain
Enforced Columns that are divergent from the domain (for certain
column properties) must be detached from the domain

Enforcing non- In a PDM, you can enforce non-divergence from a domain for the following
divergence for column properties that are listed below the Enforce non-divergence checkbox
column properties in Model Options:

Property Columns using the domain cannot have divergent


Data type Data type, length, and precision
Check Check parameters
Rules Business rules
Mandatory Mandatory values

If you modify domain non-divergence options, these changes apply only to


the current PDM.
Updating column You can select the column properties that you want to be updated for all
properties column using a domain, when that domain is modified.

44
Chapter 3 Building Physical Data Models

Your selection to enforce, or not to enforce, non-divergence between a


domain and the columns using the domain definition, has the following
results:

Non-divergence Property is… Result when domain is modified


Enforced Selected Property is updated for all columns using
domain
Not selected No property is updated
Not enforced Selected You must confirm property update for all
columns using domain
Not selected No property is updated

$ For information on selecting model options for columns and domains


see the section Defining PDM options in the chapter Physical Data Model
Basics.

v To enforce domain non-divergence:


1 Select Tools➤Model Options.
or
Right click the diagram background.
Select Model Options from the context menu.
The Model Options dialog box opens to the Model page.

45
Defining domains

2 Select the Enforce non-divergence checkbox in the Column and Domain


groupbox.
3 Select checkboxes for the column properties that are not permitted to
diverge from the domain definition.
4 Clear checkboxes for column properties that are permitted to diverge
from the domain definition.
5 Click OK.

46
Chapter 3 Building Physical Data Models

Using abstract data types


An abstract data type (ADT) is a user defined data type which can
encapsulate a range of data values and functions. The functions can be both
defined on, and operate on the set of values.
Example An abstract data type for the Gregorian calendar which has functions defined
to do the following:
♦ Read and write roman numerals
♦ Convert dates from the Julian calendar to the Gregorian calendar
♦ Convert dates from the Gregorian calendar to the Julian calendar

Types of abstract data types used in PowerDesigner


Depending on the current DBMS, the following groups of abstract data types
can be represented in PowerDesigner:

Type Description Example


Array Fixed length collection of elements VARRAY (Oracle 8)
List Unfixed length collection of objects TABLE (Oracle 8)
Java Java class JAVA (Adaptive Server
Anywhere 6, and Adaptive
Server Enterprise)
Object Contains a list of attributes OBJECT (Oracle 8)
Structured Contains a list of attributes NAMED ROW TYPE
(Informix 9.x, and IBM
DB2 5.2)

47
Using abstract data types

How are abstract data types used in PowerDesigner?


Abstract data types can be used in the following ways in a PDM:

Abstract data
type is Description
Created You can create an abstract data type for each category
supported by the current DBMS. If you create a abstract data
type of type JAVA, you can link it to a Java class in an OOM
to access the Java class properties
Reverse Declaration of an abstract data type is reverse engineered into
engineered a PDM

You create abstract data types in the List of Abstract Data Types. When you
reverse engineer a database that contains abstract data types, the data type is
automatically added to the List of Abstract Data Types.
An abstract data type must be listed in the List of Abstract Data Types before
it is available as a data type for columns and domains in the PDM.
$ For more information on reverse engineering a database into a PDM,
see the chapter Reverse Engineering.

Linking Java classes


Java classes can not be created in the PDM. You need to specify an
abstract data type as type JAVA, and then link it to an existing Java class
in the OOM. Once a Java class is linked, you can access its properties.

$ For more information on linking Java classes, see the section Linking
an abstract data type to a Java class.
Linking to Java You cannot create a Java class in a PDM. You need to specify the name and
classes in the code of a Java class in the List of Abstract Data Types, then link it to a Java
object-oriented class in a PowerDesigner Object-Oriented Model. The OOM must be open in
model the current Workspace. Once an abstract data type is linked to a Java class,
you can access the Java class property sheet.
Automatic linking You can reverse engineer a database that contains Java classes into a PDM.
of reversed Java To have access to the Java class properties, you must also reverse engineer
classes the Java classes into an OOM. The columns or domains that use the Java
classes as data types in the PDM are then automatically linked to the
corresponding Java classes in the OOM.
$ For more information on creating and reverse engineering Java classes
into a PowerDesigner Object-Oriented Model, see the PowerDesigner
Object-Oriented Model User’s Guide.

48
Chapter 3 Building Physical Data Models

Abstract data type properties


The definition of an abstract data type includes the following properties:

Property Description Length


Name Name for abstract data type 254
Code Reference code for abstract data type 254
Comment Descriptive label 32Kb
Type Defining group that includes the abstract data —
type

Depending on its type, an abstract data type definition can also include the
following properties:
♦ Data type, length, and precision
♦ Size (for arrays)
♦ Linked class name (for Java types)
♦ File name and path, which contains the declaration of the class

Creating an abstract data type


You can create an abstract data type from the List of Abstract Data Types. If
the current DBMS does not support abstract data types, the menu item is
disabled.
When you create an abstract data type it then becomes available to be used as
a data type for columns and domains in the PDM.

Linking Java classes


Java classes can not be created in the PDM. You need to specify an
abstract data type as type JAVA, and then link it to an existing Java class
in the OOM. Once a Java class is linked, you can access its properties.

49
Using abstract data types

v To create an abstract data type:


1 Select Model➤Abstract Data Types.
The List of Abstract Data Types appears.

2 Click a new line in the list.


or
Click the Add a Row tool.
An arrow appears at the beginning of the line.
3 Type an abstract data type name and code.
4 Click Apply.
The creation of the new abstract data type is committed.
5 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.
The abstract data type property sheet opens to the General page.
6 Select a type of abstract data type from the Type dropdown listbox.

50
Chapter 3 Building Physical Data Models

Depending on the type of abstract data type that you select, other
property boxes or page tabs may appear on the property sheet. For
example, the property sheet for an VARRAY in Oracle 8 shows the
properties Data Type, Size, Length, and Precision.

7 Type or select data type properties.


8 Click OK.

Linking an abstract data type to a Java class


You can specify a Java class in the PDM, then link it to a Java class in a
PowerDesigner OOM. The OOM must be open in the current Workspace to
be linked.
When you link an abstract data type to a Java class, a shortcut is created
which allows you to access the properties of the Java class.

v To link an abstract data type to a Java class:


1 Select Model➤Abstract Data Types.
The List of Abstract data Types appears.
2 Click a line in the list for an abstract data type of the type JAVA.
An arrow appears at the start of the line.
3 Click the Properties tool.

51
Using abstract data types

or
Double-click the arrow at the start of the line.
The abstract data type property sheet appears.

4 Click the Ellipsis button at the end of the Class box.

52
Chapter 3 Building Physical Data Models

A Java class selection box appears. It lists all the Java classes that are
available in the PowerDesigner object-oriented models that are currently
open in the Workspace.

5 Select a Java class.


6 Click OK.
You return to the abstract data type property sheet. The Class name
appears in the Class box. The abstract data type is now linked to this
Java class.
7 Click the Properties button at the end of the Class box.

53
Using abstract data types

A shortcut property sheet for the Java class appears.

8 Click the Properties button at the end of the Target Object box.
The target class property sheet appears.

9 Click OK.
You return to the shortcut property sheet.
10 Click Close

54
Chapter 3 Building Physical Data Models

11 Click OK in each of the dialog boxes.

Automatic linking to a Java class after reverse engineering


When you reverse engineer a database that contains Java classes into a PDM,
the Java classes are reverse engineered as abstract data types of the type
JAVA.
The abstract data types of the type JAVA in the PDM are automatically
linked to the Java classes in the OOM as follows :
♦ You need to reverse engineer the Java classes in the database that are
used as data types for the columns and domains in an OOM
♦ You reverse engineer the database into a PDM
♦ PowerDesigner automatically searches the open OOMs for the Java
classes that correspond to the JAVA abstract data types in the PDM and
makes the corresponding link
The Java classes that are reverse engineered into a PDM are listed
automatically as abstract data types of type JAVA in the List of Abstract Data
Types.
You can access the properties of a Java class from the property sheet of the
corresponding abstract data type of type JAVA.
$ For more information on accessing the property sheet of a linked Java
class, see the section Accessing a linked Java class in an OOM.

Accessing a linked Java class in an OOM


You can access the property sheet of a Java class in an OOM that is linked to
an abstract data type of the type JAVA in the PDM. The OOM must be open
in the current Workspace.

v To access a linked Java class in an OOM:


1 Select Model➤Abstract Data Types.
The List of Abstract data Types appears.
2 Click a line in the list for an abstract data type of the type JAVA.
An arrow appears at the start of the line.
3 Click the Properties tool
or

55
Using abstract data types

Double-click the arrow at the start of the line.


The abstract data type property sheet appears. The linked class name
appears in the Class box. The abstract data type is linked to this Java
class.

4 Click the Properties button at the end of the Class box.


A shortcut property sheet for the Java class appears.

5 Click the Properties button at the end of the Target Object box.

56
Chapter 3 Building Physical Data Models

The target class property sheet appears.

6 Click OK.
You return to the Shortcut property sheet.
7 Click Close
8 Click OK in each of the dialog boxes.

57
Defining columns

Defining columns
A column contains an individual data item within a row. It is the model
equivalent of a database column. A column is always defined for a table.
When you create a column, it must be assigned a name and code. You can
also select a data type for the column. This can be done directly from a list of
available data types, or by attaching the column to a domain.

58
Chapter 3 Building Physical Data Models

Column properties
Each column definition includes the following properties:

Maximum
Property Description length
Name Name for the column. This name improves the 254
readability of the model
Code Reference code for the column 254
Comment Descriptive label for the column 32K
Table Table which contains column
Data type Form of the data corresponding to the column, 30
such as numeric, alphanumeric, boolean, or others
Length Maximum length of the data type —
Precision Maximum number of places after the decimal 1000
point
Domain Name of the associated domain —
Primary key When selected, designates a column whose values —
uniquely identify a row in the table
Foreign key When selected, designates a column that depends —
on and migrates from a primary key column in
another table
Mandatory When selected, indicates a column that must be —
assigned a value
Identity (For Sybase System 10, Sybase System 11, and —
MS SQL Server 6 only). When selected, indicates
that the data is auto-incremented
With default (For Ingres, DB2, SQLBase, Xdb, Datacom, and —
OpenIngres only) When selected, indicates if a
default value is assigned to the column when a
Null value is inserted

59
Defining columns

A column definition also includes the following properties, each with their
respective property sheets:

Property Description
Detail Column fill parameters. These determine the percentage of
column entries for which a null value is permitted, and the
percentage of column rows that contain unique values
Standard checks Standard check parameters
Additional checks SQL expression defining a check parameter

Creating a column
A column is always defined for a table. When you create a column you must
assign it a name and a code.

v To create a column:
1 Double-click a table in the model.
The table property sheet appears.
2 Click the Columns tab.
The Columns page appears. It lists columns defined for the table.

60
Chapter 3 Building Physical Data Models

3 Click a blank line in the list.


or
Click the Add a Row tool.
An arrow appears at the beginning of the line.
4 Type a column name and a column code.
5 Click OK.

Selecting a data type for a column


There are two ways to select a data type for a column:
♦ Attach the column to a domain The domain dictates a data type, a
length, and a level of precision, as well as optional check parameters
♦ Manually select a data type You select a data type along with a length,
a level of precision, and optional check parameters

About check parameters


Check parameters indicate data ranges and validation rules. You can set
check parameters for domains, tables, and columns.

v To select a data type for a column:


1 Double-click a table in the diagram.
The table property sheet appears.
2 Click the Columns tab.
The Columns page appears. It lists columns associated with the table.
3 Click the column that you want to define.
An arrow appears at the beginning of the line.
4 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.

61
Defining columns

The column property sheet opens to the General page.

Opening property sheets at last accessed page


Property sheets open to the General page by default. However, you
can choose to open property sheets at the last page accessed by
selecting Tools➤Options➤Dialog, and selecting the option Keep
Last Tab in the Property Sheets groupbox.

5 Select a data type from the Data Type dropdown listbox.


or
Click the Question mark button at the end of the Data Type listbox.
A list of standard data types appears.
Select the radio button corresponding to the data type you want to apply.
Click OK
6 Type the data type length in the Length box.
or
Type the level of data type precision in the Precision box.

Undefined data type


If you do not want to select a data type immediately, you can choose
the <undefined> data type. When you generate the database, this data
type is replaced by the default data type for your database, as defined
in the DBMS.

62
Chapter 3 Building Physical Data Models

7 Click OK.
You return to the Columns page. The new data type for the column
appears in the Data Type column.
8 Click OK.
or
Click another column in the list.

Attaching a column to a domain


If you attach a column to a domain, the domain supplies the data type and
related data characteristics. It may also indicate check parameters, and
business rules.

v To attach a column to a domain:


1 Double-click a table in the model.
The table property sheet appears.
2 Click the Columns tab.
The Columns page appears listing columns associated with the table.
3 Click a column in the list.
An arrow appears at the beginning of the line.
4 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.

63
Defining columns

The column property sheet opens to the General page.

Opening property sheets at last accessed page


Property sheets open to the General page by default. However, you
can choose to open property sheets at the last page accessed by
selecting Tools➤Options➤Dialog, and selecting the option Keep
Last Tab in the Property Sheets groupbox.

5 Select a domain from the Domain dropdown listbox at the bottom of the
dialog box.
6 Click OK.
You return to the Columns page. In the Data Type column, the domain’s
data type replaces the data type previously defined for the column.
7 Click OK.
or
Click another column in the list.

64
Chapter 3 Building Physical Data Models

Copying a column to another table


You can copy a column from one table and add it to another table. If the table
already contains a column with the same name or code as the copied column,
the copied column is renamed. For example the column PUB_ID is renamed
PUB_ID2 when it is copied to a table which already contains a column
PUB_ID.

v To copy a column to another table:


1 Double-click a table in the model.
The table property sheet appears.
2 Click the Columns page.
The Columns page appears.
3 Click the Add Columns tool.
A selection box appears. It lists columns attached to all other tables in
the model.

4 Select one or more columns in the list.


5 Click OK.
The copied columns appear in the list of columns for the current table.
6 Click OK.

65
Defining columns

Making a column mandatory or optional


If a column is mandatory, every table row must have a value for that column.
If a column is not mandatory, table rows do not have to have a value for that
column.
By default, all primary key columns are mandatory.

v To define a column as mandatory or optional:


1 Select Model➤Columns.
The List of Columns appears.
2 Click a column in the list.
An arrow appears at the beginning of the line.
3 Select the Mandatory checkbox to make the column mandatory.
or
Clear the Mandatory checkbox to make the column optional.
4 Click OK.

Naming a column constraint


A column constraint is a named check that enforces data requirements of
check parameters.
Whenever you place a data restriction on a column, it generates a constraint
automatically. You have the option of specifying a name for the constraint. If
you do not specify a name for the constraint, PowerDesigner creates a default
constraint name automatically.
This name helps you to identify and customize a column constraint in scripts
for database creation and modification.

v To name a column constraint:


1 Select Model➤Columns.
The List of Columns appears.
2 Click a column in the list.
An arrow appears at the start of the line.
3 Double-click the arrow at the start of the line.
or
Click the Properties tool.

66
Chapter 3 Building Physical Data Models

The column property sheet appears.


4 Click the Additional Checks tab.
The Additional Checks page appears.
5 Type changes to the constraint name in the Constraint Name box.
The User-Defined button at the end of the box is pressed automatically.

Undo changes to a constraint name


You can always return to the default constraint name by clicking the
User-Defined button.

6 Click OK in each of the dialog boxes.

Configuring the display of the list of columns

You can sort the columns in the list in two ways:


♦ By any property that appears in the title bar of the property lists
♦ Alphabetical or reverse alphabetical order
The listed order is indicated by an arrow head that appears at the end of the
title bar of the property column. Each time you click a title bar, you change
the listed order for that column, according to the displayed arrow.
Each arrow type corresponds to the following list orders:

Arrow type Listed order


Down arrow Alphabetically
Up arrow Reverse alphabetically

For example, when you click the title bar Name, the columns are listed by
column name alphabetically when the down arrow is indicated, and in reverse
order when the up arrow is indicated.

v To configure the display of the list of columns:


1 Select Model➤Columns.
The List of columns appears.
2 Click a property title bar.

67
Defining columns

The listed columns are ordered by the indicated property.


3 Click OK.

68
Chapter 3 Building Physical Data Models

Defining keys
A key is a column, or a combination of columns, that uniquely identifies a
row in a table. Each key can generate a unique index or a unique constraint in
a target database.
The PDM supports the following types of keys:

Key Description
Primary Column or combination of columns whose values uniquely identify
every row in a table. A table can have only one primary key
Alternate Column or combination of columns (not the same column or
combination of columns as for a primary key) whose values
uniquely identify every row in a table
Foreign Column or combination of columns whose values are required to
match a primary key, or alternate key, in some other table

Example The TITLE table shown below has a primary, alternate and foreign key:
♦ TITLE_ID is the primary key and consists of the column TITLE ISBN
which identifies each book title in the table
♦ TITLE_NAME is an alternate key containing the columns TITLE
NAME and TITLE TYPE. It allows each title to be identified by its
name and type, The fact that it is an alternate key indicates that there is a
constraint that no two titles of the same type can have the same name
The TITLE table also contains the foreign key column PUBLISHER ID. This
column references the primary key column in the Publisher table.

69
Defining keys

Designating a primary key


A primary key is a key which has been designated as the primary identifier
for a table. A primary key is made up of one or more columns whose values
uniquely identify every row in the table.
Every table must have a primary key, composed of one or more of its
columns.
Example Employee number is the primary key for the table Employee. This means that
each employee must have one unique employee number.

You can define one or more columns as the primary key of a table from the
list of columns.

v To designate a primary key:


1 Double-click a table in the model.
The table property sheet appears.
2 Click the Columns tab.
The Columns page appears. It lists the columns associated with the table.
3 Select one or more columns in the list.
4 Select the checkbox in the P column.
5 Click OK.

Designating a foreign key


A foreign key is a primary key, or an alternate key, that migrates from
another table. Depending on selected model options, a primary key can be
automatically migrated to a child table as a foreign key at reference creation.
The columns that are defined in a foreign key can also be user specified at
creation and changed at any time from the Joins page of the reference
property sheet.
$ For more information on the auto-migration of a foreign key, see the
section Auto-migrating foreign keys.

70
Chapter 3 Building Physical Data Models

$ For more information on defining references, see the section Defining


references.

Adding parent table columns to a key


You can add existing columns in the parent table to a primary key or an
alternate key.

v To add parent table columns to a key:


1 From the General page for a key, click the Columns tab.
The Columns page appears. It lists the columns defined for the key.
2 Click the Add Columns tool.
A selection box appears. It list the columns available for selection in the
parent table.
3 Select one or more columns.
4 Click OK.
The new column names appear in the list of columns defined for the key.
5 Click OK on each of the dialog boxes.

Auto-migrating foreign keys


When you create a reference, the primary key in the parent table is
automatically migrated to the child table as a foreign key when the following
model options are selected:
♦ Auto-migrate Columns
♦ Default Link on Creation: Primary Key
When you select Auto-migrate columns, you can also choose to automatically
migrate the following column properties:
♦ Domains
♦ Check parameters
♦ Validation rules
Column properties that are not selected are not migrated automatically at
reference creation.

71
Defining keys

The following table shows the results of different actions when you choose to
auto-migrate foreign key columns:

Action Result
Modify reference Migrate primary key in parent table to foreign key in child
attach point table
Delete unused foreign key columns
Modify reference join
Delete primary Delete corresponding foreign key and reference join
key

v To auto-migrate foreign keys:


1 Select Tools➤Model Options.
The Model options dialog box appears.

2 Select the Auto-migrate Columns checkbox in the Reference groupbox.


3 Select or clear the Domain, Check, and Rules checkboxes.
4 Click OK

72
Chapter 3 Building Physical Data Models

Designating an alternate key


An alternate key is made up of one or more columns whose values uniquely
identify every row in the table, and is not a primary key. Each alternate key
can generate a unique index or a unique constraint in a target database.
An alternate key can also be a foreign key. An alternate key cannot be a
primary key.

v To designate an alternate key:


1 Double-click a table in the model.
The property sheet for the table appears.
2 Click the Keys tab.
The Keys page appears. It lists keys defined for the table.
3 Click a blank line in the list.
or
Click the Add a Row tool.
An arrow appears at the beginning of the line.
4 Type a key name and a key code.

Alternate key naming convention


The naming convention for an alternate key is AK followed by the
number of the key column code; for example AK1_CUSNAME.

5 (Optional) Type a constraint name.


If you do not specify a constraint name, PowerDesigner creates a default
constraint name automatically.

Constraint name column not visible


To make the Constraint Name column visible in the list, click the
Customize Columns and Filter tool at the top of the Keys page, select
the Constraint Name checkbox from the list of filter options that
appears, and click OK.

6 Click Apply.
The constraint name and code are committed.
7 Click the new key name.
An arrow appears at the beginning of the line.

73
Defining keys

8 Click the Properties tool.


The property sheet for the new key appears.
9 Click the columns tab.
The columns page appears. It lists all columns defined for the key. At
key creation, the list is empty.
10 Click the Add Columns tool.
A list of columns, defined for the table appears. This list does not
include primary key columns.
11 Select checkboxes for one or more columns that you want to designate as
alternate key columns.
12 Click OK in each of the dialog boxes.

Naming key constraints


Naming key constraints helps you to identify and customize key constraints
in scripts for database creation and modification. The constraint name gives
you greater flexibility for modifying keys in subsequent database generations.
If you do not specify a constraint name, PowerDesigner creates a default
constraint name automatically.

Naming a primary key constraint


A primary key constraint is a named check that enforces the uniqueness and
the presence of values in a primary key column.
In the name of a primary key constraint, you can use the following variable:

Variable Description
%TABLE% Code of the table

$ For a full list of all variables that can be used in PowerDesigner, see the
appendix PowerDesigner Variables.

v To name a primary key constraint:


1 Double-click a table in the model.
The table property sheet appears.
2 Click the Keys tab.

74
Chapter 3 Building Physical Data Models

The Keys page appears. It lists keys defined for the table.
3 Select the primary key.
4 Click the Properties tool.
The property sheet for the primary key appears.
5 Type changes to the name in the Constraint Name box.
The User-Defined button at the end of the Constraint box is pressed
automatically.

Undo changes to a constraint name


You can always return to the default constraint name by re-clicking
the User-Defined button.

6 Click OK in each of the dialog boxes.

Naming a foreign key constraint


In the name of a foreign key constraint, you can use the following variables:

Variable Description
%REFRNAME% Name of the reference
%REFRCODE% Code of the reference
%PARENT% Code of the parent table
%CHILD% Code of the child table

$ For a full list of all variables that you can use in PowerDesigner, see the
appendix Variables in PowerDesigner.

v To name a foreign key constraint:


1 Double-click a reference in the model.
The property sheet for the reference appears.
2 Click the Integrity tab.
The Integrity page appears. It displays referential integrity information
for the reference.
3 Type changes to the name in the Constraint Name box.
The User-Defined button at the end of the Constraint box is depressed
automatically.

75
Defining keys

Undo changes to a constraint name


You can always return to the default constraint name by re-clicking
the User-Defined button.

4 Click OK in each of the dialog boxes.

Naming an alternate key constraint


In the name of an alternate key constraint, you can use the following
variables:

Variable Description
%AK% Code of the alternate key
%AKNAME% Name of the alternate key
%TABLE% Code of the table

$ For a full list of all variables that you can use in PowerDesigner, see the
appendix Variables in PowerDesigner.

v To name an alternate key constraint:


1 Double-click a table in the model.
The table property sheet appears.
2 Click the Keys tab.
The Keys page appears. It lists keys defined for the table.
3 Select an alternate key.
4 Click the Properties tool.
The property sheet for the alternate key appears.
5 Type changes to the name in the Constraint Name box.
The User-Defined button at the end of the Constraint box is depressed
automatically.

Undo changes to a constraint name


You can always return to the default constraint name by re-clicking
the User-Defined button.

6 Click OK in each of the dialog boxes.

76
Chapter 3 Building Physical Data Models

Defining references
A reference is a link between a parent table and a child table. It defines a
referential integrity constraint between column pairs for a primary key, or
alternate key, and a foreign key, or between user specified columns in both
tables.
When column pairs are linked by a reference, each value in the child table
column refers to an equivalent value in the parent table column.
Within a reference, each column pair is linked by a join. Depending on the
number of columns in the primary key, or alternate key, or the number of
specified columns, a reference can contain one or more joins.
A reference normally links primary key, or alternate key, columns to foreign
key columns.
Example The two tables SALE and STORE are linked by a reference. STORE is the
parent table and SALE is the child table. The reference contains a join which
links the primary key column STORE ID (the referenced column) to the
foreign key column STORE ID (the referencing column).

Linking keys and Depending on its properties, a reference can link a parent table and a child
user-specified table in two ways:
columns
Reference links Description
Primary key, alternate key Primary or alternate key in the parent table is
and foreign keys linked to a foreign key in the child table
User specified columns One or more columns in the parent table are linked
to corresponding columns in the child table. The
linked columns in both tables are specified by the
user, and are linked independently of primary key,
alternate key, and foreign key columns

77
Defining references

Reference properties
The definition of a reference includes the following properties:

Maximum
Property Description length
Name Name for the reference. This name 254
improves the readability of the model
Code Code for the reference 254
Comment Descriptive label for the reference 32Kb
Parent table Parent table of reference. This table —
contains the primary key, or alternate
key, linked by the reference
Child table Child table of reference. This table —
contains the foreign key linked by the
reference
Generate When selected, indicates to generate the —
reference in the database
Joins Links between parent table columns and —
child table columns
Integrity Integrity constraints defined for reference —

78
Chapter 3 Building Physical Data Models

Defining model options for references

You can define the following model options for references:

Option Result when selected Result when cleared


Unique code Each reference has a unique code Different references can
in the namespace have the same code
(except when two
references share the same
child table)
Auto-reuse An existing column in child table is No child table columns are
columns used as foreign key column when reused as foreign key
all of the following conditions columns
apply:
♦ Child column has same code as
migrating primary key column
♦ Child column is not already a
foreign key column
♦ Data types are compatible
Auto-migrate Primary key columns are Primary key columns are
columns automatically migrated to foreign not automatically migrated
key columns at reference creation
or when definition of primary key
changes
*Domain Domain automatically migrated Domain not automatically
with primary key columns migrated with primary key
columns
*Check Check parameter automatically Check parameters not
migrated with primary key columns automatically migrated
with primary key columns
*Rules Business rule automatically Business rules not
migrated with primary key columns automatically migrated
with primary key columns
Default link Reference links Primary key —
on creation: columns to foreign key columns at
Primary key creation
Default link No columns are linked at creation. —
on creation: No joins are created.
User-defined

* Only available when Auto-migrate Columns is selected.

79
Defining references

v To define a model option for references:


1 Select Tools➤Model Options.
or
Right-click the diagram background and select Model Options from the
context menu.
The Model Options dialog box opens to the Model page.

2 Select or clear check boxes for model options in the Reference


groupbox.
3 Click OK.

Automatic reuse and migration of columns


You can select options from the Model Options page to automatically
migrate primary key columns to foreign key columns. You can also choose to
automatically reuse an existing child table column as a foreign key column.
Auto-migrate From Model Options, you can choose to automatically migrate primary key
columns columns to foreign key columns at reference creation by selecting both the
following options:
♦ Default Link on Creation: Primary key
♦ Auto-migrate Columns

80
Chapter 3 Building Physical Data Models

Auto-reuse From Model Options, you can choose to automatically reuse an existing child
columns table column as a foreign key column by selecting the following model
options:
♦ Default Link on Creation: Primary key
♦ Auto-reuse Columns
The Child table column must have the same code as the migrating primary
key column, and can not already be a foreign key column.
PowerDesigner does not automatically reuse existing foreign key columns.
This must be done manually from the Joins page of the reference property
sheet.
Matching child The following table shows the results of migrating primary key columns to a
table column exists child table that contains a matching column for one of the primary key
columns. The original two tables are also shown below:

Auto- Auto- Description of


reuse migrate Result child table
Selected Selected Col_1 is reused and
Col_2 is created

Not Selected T1_Col_1 is created


selected and Col_2 is created

Selected Not selected Col_1 is reused and


Col_2 is not created

Not Not selected No column is reused


selected and no column is
created

81
Defining references

Matching child The following table shows the results of migrating primary key columns to a
table column is child table that contains a matching child table column that is already a
already a FK foreign key column for another table. The original two tables are also shown
column below:

Auto- Auto- Result Description of


reuse migrate child table
Selected Selected T1_Col_1 is created
and Col_2 is created

Unselected Selected T1_Col_1 is created


and Col_2 is created

Selected Not selected No columns are


reused or created

Unselected Unselected No columns are


reused or created

Creating a reference
You can create a reference that links a primary key, or alternate key, to a
foreign key, or user-specified columns in both parent and child tables.
When you create a reference, its properties depend on the current model
options, and the existence, or non-existence, of a foreign key column in the
child table with the same code as a migrating primary key column.
$ For more information on selecting model options for references see the
sections Defining model options for references.
$ For more information on column migration and reuse, see the section
Auto-migrating foreign keys.

82
Chapter 3 Building Physical Data Models

v To create a reference:
1 Click the Reference tool in the tool palette.
2 Drag the reference link from the child table to the parent table containing
the primary key, or alternate key, to migrate.
The link appears between the two tables.

Dragging a reference to a different table


You can change the table at either end of a reference by clicking the
reference and holding down CTRL as you drag one of its attach points
to a different table.

3 Click the Pointer tool.


or
Click the right mouse button.
You release the Reference tool.
4 Double-click the new link in the model.
The reference property sheet appears.

5 Type a reference name and a reference code.

83
Defining references

6 Select the Generate checkbox if you want to generate the reference.


or
Clear the Generate checkbox if you do not want to generate the
reference.
7 Click OK.

Defining reference joins


A join is a link between a column in a parent table and a column in a child
table (column pair) that is defined within a reference.
A join can link primary key, or alternate key, and foreign key columns, or
user specified columns in the parent and child tables that are independent of
key columns.
Default joins at When you create a reference, the current selections for Model Options
reference creation determine the creation of the following types of default joins:
♦ Joins that link primary and foreign key column pairs
♦ Joins that are linked to primary key columns, but are not linked to child
table columns, so are incomplete
♦ No joins created
Join creation is determined by the following selections for Model Options:

Default Link on Auto-migrate


Creation Columns Result
Primary Key Selected Joins created between primary and
foreign key columns
Primary Key Not selected Joins are created that are linked to
primary key columns, but are
incomplete. Foreign key columns must
be specified manually
User-defined Selected No joins created. Parent and child table
column pairs must be specified
manually
User-defined Not selected No joins created. Parent and child table
column pairs must be specified
manually

84
Chapter 3 Building Physical Data Models

Linking columns in For any reference you can choose to link a primary key, or alternate key, to a
a primary or corresponding foreign key. When you select a key from the Joins page of the
alternate key reference property sheet, all the key columns are linked to matching foreign
key columns in the child table.

Changing a foreign key column link


A foreign key column can also be changed to link to another parent table
column, either within the key relationship, or independent of it.

Reuse and You can use the following buttons on the Joins page to reuse or migrate
Migration option for columns linked by joins.
a selected
reference Button Name Description
Reuse Columns Reuse existing child columns with same code as
parent table columns
Migrate Columns Migrate key columns to foreign key columns. If
columns do not exist they are created
Cancel Migration Delete any migrated columns in child table

v To define joins in a reference:


1 Double-click a reference in the model.
The reference property sheet appears.
2 Click the Joins tab.

85
Defining references

The Joins page appears.

3 Select a key from the Parent Key dropdown listbox to create joins
between primary key, or alternate key, and foreign key columns.
or
Select <NONE> from the Parent Key dropdown listbox to create joins
between user-specified columns.
The columns linked by the joins are listed in the Parent Table and Child
Table columns. If you selected <NONE>, the column lists are empty.

Changing a foreign key column linked by a join


You can change the foreign key column linked by a join by clicking
the column in the Child Table list, and selecting another column from
the dropdown listbox.

4 <Optional> If you selected <NONE> from the Parent Key dropdown


listbox, click a parent table column and select a column from the
dropdown listbox, then click the child table column and select a child
column.
5 Click OK

86
Chapter 3 Building Physical Data Models

Changing a table at either end of a reference


After reference creation you can change one table, or both of the tables,
linked by a reference, using one of the following methods:
♦ Dragging a reference end to another table in the diagram
♦ Selecting a different table from the reference property sheet
♦ Selecting a different table from the list of references

Changing a referenced table graphically

v To change a referenced table graphically:


♦ Click the reference and hold down CTRL as you drag one of its attach
points to a different table

Selecting a different table for a reference from a property sheet

v To select a different table from the property sheet:


1 Double-click a reference in the diagram.
The reference property sheet appears.
2 Select a parent table from the Parent Table dropdown list.
or
Select a child table from the Child Table dropdown list.
3 Click OK.

Selecting a different table for a reference from the list

v To select a different table from the list:


1 Select Model➤References
The List of References appears.
2 Click a reference in the list.
An arrow appears at the beginning of the line.
3 Click the reference line in the Parent column.
Select a parent table from the dropdown list that appears.
or
Click the reference line in the Child column.
87
Defining references

Select a child table from the dropdown list that appears.


4 Click OK.

Sorting the list of references

You can sort the list of references alphabetically or in reverse alphabetical


order by any list property.
The listed order is indicated by an arrow head that appears at the end of the
column heading for the property as follows:

Arrow type Listed order


Down arrow Alphabetically
Up arrow Reverse alphabetically

For example, when you click the column heading Name, the references are
listed by reference name alphabetically when the down arrow is indicated,
and in reverse order when the up arrow is indicated.

v To display and sort the list of references:


1 Select Model➤References.
The List of References appears.
2 Click a column heading.
The listed references are ordered by the indicated property.
3 Click OK.

88
Chapter 3 Building Physical Data Models

Rebuilding references
Rebuilding references in a PDM creates default references between tables
with matching key columns.
Rebuilding references is useful following the reverse engineering of a
database in which all of the references could not be reverse engineered.
You can choose to rebuild references in one of two ways:

Rebuild option Description


Delete and rebuild All existing references are deleted, and new references built
based on matching key columns
Preserve All existing references are kept, and new references built
based on new matching key columns

You can choose to rebuild all references in your model, or select the tables
that are linked by the references that you want to rebuild.

v To rebuild references:
1 Select Tools➤Rebuild References.
The Rebuild References dialog box appears.
2 Select the Delete and Rebuild radio button.
or
Select the Preserve radio button.
3 Click the Selection tab.

89
Defining references

A selection page appears. It lists all the tables in the current model.

Rebuilding references in a package


To rebuild references between tables in a package, select the package
from the dropdown listbox at the top of the page.
To rebuild references between tables in a sub-package, select the
Include Sub-Packages icon next to the dropdown listbox, and then
select a sub-package from the dropdown list.

4 Select checkboxes for tables linked by references that you want to


rebuild.
or
Clear checkboxes for tables linked by references that you do not want to
rebuild.

Selecting or clearing all checkboxes


You can select all checkboxes, or clear all checkboxes, by selecting
the Select All tool, or Clear All tool, from the toolbar at the top of the
page.

5 Click OK.
If you selected the Delete and Rebuild mode, a confirmation box asks
you to confirm your choice. If you selected the Preserve mode, you do
not receive a confirmation box.
6 Click Yes to confirm the deletion and rebuild of the selected references.

90
Chapter 3 Building Physical Data Models

Using referential integrity


Referential integrity is a collection of rules that govern data consistency
between primary keys, alternate keys and foreign keys.
Referential integrity dictates what happens when you update or delete a value
in a referenced column in the parent table, and when you delete a row
containing a referenced column from the parent table.
You can implement referential integrity using one of two methods:

Referential integrity Description


Declarative Referential integrity constraints are defined for
particular references. When the reference is generated
the target DBMS evaluates the reference validity and
generates appropriate error messages
Using triggers Referential integrity constraints are implemented by
triggers based on the integrity constraints defined in
the reference property sheet. The trigger evaluates
reference validity and generates appropriate user-
defined error messages

Referential integrity as a generation option


For certain target databases you can define referential integrity as a
generation option. However many databases do not accept referential
integrity as a generation option (in a trigger or a declaration). In these
cases, when you generate a database generation script, it does not include
the definition of referential integrity.

91
Defining references

Referential integrity properties


The definition of referential integrity includes the following properties:

Property Description
Constraint name Name of the referential integrity constraint. Maximum
length is 254 characters
Implementation Indicates whether implementation of referential integrity is
declarative, or by the use of triggers
Cardinality Indicates the maximum and minimum number of instances
in a child table that can appear for each corresponding
instance in the parent table
User-defined Indicates a user-defined constraint name
Update constraint How updating a key value, in the parent table affects the
foreign key value in the child table
Delete constraint How deleting a row in the parent table affects the child table
Mandatory parent Each foreign key value in the child table must have a
corresponding key value, in the parent table
Change parent A foreign key value can change to select another value in
allowed the referenced key in the parent table
Check on commit* Verifies referential integrity only on the commit, instead of
verifying it after row insertion. You can use this feature to
control circular dependencies
* Only available for Sybase SQL Anywhere 5.0 and 5.5.

Cardinality Defining cardinality allows you to control the minimum and maximum
number of children permitted for each parent. You can use the following
values to define cardinality:

92
Chapter 3 Building Physical Data Models

Cardinality Minimum Maximum


0 A parent does not have a minimum —
number of children. Child is
optional
1 At least one child must exist for Only one child can exist
each parent for each parent
any integer Minimum number is the number Maximum number is the
indicated number indicated
N or * — Any number of children
can exist for a each parent

Cardinality format Cardinality can be expressed in the following formats:

Format Description Example


x..y Minimum and maximum (2..10) There must exist between two
interval, where x is any and ten children for each parent
integer, and Y can be any
(0..n) Child is optional, and there can
of the following:
be any number of children for any one
Integer parent
n (infinite)
10* There must exist at least ten
* (infinite)
children for each parent
y Maximum value which is (10) There can be up to ten children for
equivalent to the form each parent. Child is optional
(0..y)
x..y, x..y Series of intervals, where (1..2, 4..n) There can exist either one or
the cardinality can be any two children for each parent, or at least
one of the intervals four children for each parent

Update and delete Update constraint and delete constraint take any of the following values:
constraints

93
Defining references

Value Change to parent table Result in child table


None Update or delete parent value None
Restrict Cannot update or delete parent None
value if one or more matching
child values exist
Cascade Update or delete parent value Update or delete matching child
values
Set null Update or delete parent value Set matching child values to
NULL
Set default Update or delete parent value Set matching child values to
default value

Defining referential integrity

You define referential integrity from the Integrity page of the reference
property sheet.

Implementing referential integrity


In PowerDesigner 6, the implementation of referential integrity was
defined as a generation option. However, in PowerDesigner 7, you
indicate the implementation of referential integrity using declarative
referential integrity, or by the use of triggers, from the Integrity page of
the reference property sheet.

v To define referential integrity:


1 Double-click a reference in the model.
The reference property sheet appears.
2 Click the Integrity tab.

94
Chapter 3 Building Physical Data Models

The Integrity page appears. If no constraint name has been defined, the
default constraint name is shown in the Constraint name box.

3 (Optional) Type a constraint name.


The User-Defined button at the end of the Constraint name box is
automatically shown pressed, to indicate the name is user-defined.

Undo changes to a constraint name


You can always return to the default constraint name by re-clicking
the User-Defined button.

4 Select Declarative from the Implementation dropdown listbox, if you


want to implement declarative referential integrity.
or
Select Trigger from the Implementation dropdown listbox, if you want to
implement referential integrity using triggers.
5 Select values for Cardinality, Update Constraint and Delete Constraint.
6 Select Mandatory Parent if you want each row in the child table to have
a corresponding row in the parent table.
7 Select Change Parent Allowed if you want to be able to update the
foreign key value in the child table.
8 Click OK.

95
Defining references

Displaying text with reference symbols


You can display the following text with reference symbols:

Label Displays
Name Name or code of the reference*
Constraint name Referential integrity constraint name
Join Statement of linked columns between the two tables
Referential integrity Update and delete referential integrity constraints.
Cardinality Minimum and maximum number of instances in a child
table that can appear for each corresponding instance in
the parent table
Implementation Implementation mode of referential integrity, declarative
or by triggers

*Displayed text depends on whether the Name or Code radio button is selected.

Referential integrity The referential integrity label indicates update and delete integrity, as
label follows:

Label Referential integrity


upd() Update
del() Delete
cpa Change Parent Allowed

96
Chapter 3 Building Physical Data Models

A letter between the parentheses indicates the type of constraint, as follows:

Label Referential integrity


() None
(R) Restrict
(C) Cascade
(N) Set null
(D) Set default

Default Cardinality The default cardinality labels for PowerDesigner indicate the minimum and
labels maximum number of children as follows:
[minimum..maximum]
For example, the cardinality label [0..n] indicates that any number of children
is acceptable.
Referential integrity The referential integrity label shown below indicates the following:
example
♦ Cascade on update
♦ Set null on delete
♦ Cardinality is 0..n (any number of children is acceptable).

v To display text with reference symbols:


1 Select Tools➤Display Preferences.
The Display Preferences dialog box opens to the Objects page.
2 Select or clear the checkboxes in the Reference groupbox.
3 Click OK.

Moving text on a reference symbol


When a reference symbol displays text, the text position is based on the
position of handles. You can add a handle on the reference symbol by
pressing CTRL while you click the symbol.

97
Defining references

Modifying a reference graphically


From the PDM graphic, you can modify a reference as follows:
♦ Bend a reference symbols
♦ Straighten a reference symbol
♦ Drag a reference to a different table
♦ Select reference display mode

Bending a reference symbol

v To bend a reference symbol:


1 Select Symbol➤Format.
The Symbol Format dialog box appears.
2 Click the Line Style tab.
The Line Style page appears.
3 Select the jagged line symbol from the Corners drop down list box.
4 Click OK.
5 Press CTRL while you click a point on the reference symbol where you
want to insert an angle.
This point becomes a handle.
6 Release CTRL.
7 Drag and drop the handle.

Straightening a reference symbol

v To straighten a reference symbol:


1 Click a reference symbol that has angles.
Handles appear on the reference symbol.
2 Press CTRL while you click a handle.
The handle and its angle disappear.

98
Chapter 3 Building Physical Data Models

Dragging a reference to a different table

v To drag a reference to a different table:


1 Click a reference symbol.
2 Press CTRL while you drag one of its attach points to a different table.

Selecting a reference display mode

v To select a reference display mode:


1 Select Tools➤Display Preferences.
The Display Preferences dialog box appears.
2 Select Reference under the Object View node in the Category tree view.
The Reference page appears.
3 Select one of the following radio buttons in the Display mode groupbox.

Mode Reference points


Relational From child to parent
CODASYL From parent to child

4 Click OK.

99
Defining indexes

Defining indexes
An index is a data structure associated with a table that is logically ordered
by the values of a key. It improves database performance and access speed.
You normally create indexes for columns that you access regularly, and
where response time is important. Indexes are most effective when they are
used on columns that contain mostly unique values.
Example In a table called Author, you create indexes for the primary key Author ID
and the column Author name, but not for the column City. The values for
city, are not likely to be unique, nor searched regularly, and do not help
reduce query time.

Index properties
Each index definition includes the following properties:

Maximum
Property Description length
Name Name of the index 254
Code Reference name of the index 254
Comment Descriptive label for the index 32Kb
Table Indicate table to index —
Type Proprietary index type (for RedBrick, Unify, and 30
Oracle only)
Unique Indicate whether an index is a unique index —
Cluster Indicate whether an index is a cluster index

An index definition also includes the following properties, which are defined
on associated property sheets:

Property Description
Columns Columns associated with index
Column Definition Indicate primary key, foreign key, or alternate key to
index. The index is associated with the columns of the
selected key
Options Physical options for the index. These are DBMS specific
Rules Business rules attached to the index

100
Chapter 3 Building Physical Data Models

Index types The following index types exist:

Type Description
User defined Identifies a row in the table for a column that is not a key column
Linked to Uniquely identifies a row in the table
primary key
Linked to Depends on and migrates from a primary key in another table
foreign key
Linked to Uniquely identifies a row in the table, which is not also indexed
alternate key by a primary key
Unique Index in which no two rows can have the same index value. All
primary key indexes must be unique
Cluster Index in which the physical order and the logical (indexed) order
is the same

One cluster index per table


A table cannot have more than one cluster index.

Creating an index
You can either create a user defined index which is associated with one or
more columns, or create an index that you link to a primary key, alternate
key, or foreign key.
Index naming Use the following naming conventions for indexes:
conventions
Index Naming convention
Primary key Table code followed by PK; for example EMPLOYEE _PK
Foreign key Table code followed by FK; for example PROJECT _ FK
Alternate key Table code followed by AK; for example EMPLOYEE _ AK

Index ascending or You can indicate the index order for each column attached to an index, by
descending order selecting or clearing the A checkbox at the end of the line, for each column
listed on the Columns page of the Index property sheet. When the A
checkbox is selected the order is ascending, when it is cleared the order is
descending.

101
Defining indexes

Creating a user-defined index

v To create a user defined index:


1 Double-click the table in the model.
The table property sheet appears.
2 Click the Indexes tab.
The Indexes page appears. It lists indexes associated with the table.

3 Click a new line in the list


or
Click the Add a Row tool.
An arrow appears at the beginning of the line.
4 Type an index name and a index code.
5 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.
The index property sheet opens to the General page.
6 Type or select Index properties.
7 Click the Columns tab.

102
Chapter 3 Building Physical Data Models

The Columns page appears. It lists columns associated with the index. At
index creation the list is empty as there are no columns yet associated
with an index.
8 Click the Add a Row tool.
A list of columns defined for the table appears.
9 Select one or more columns.
Click OK.
You return to the Columns page. The columns associated with the index
appear in the column list.
10 Select the A checkbox at the end of the column line, if you want index
entries to be in ascending order for that column.
or
Clear the A checkbox at the end of the column line, if you want index
entries to be in descending order for that column.
11 Click OK in each of the dialog boxes.

Creating an index linked to a key


When you link an index to a primary key, alternate key or a foreign key, the
index is automatically updated when the key column or columns are
modified.
Example A table contains a compound primary key. This is a primary key designated
to more than one column in a table. You create an index and link it to the
primary key. If one of the primary key columns is deleted, the corresponding
index associated with the column is also deleted.

v To create an index linked to a key:


1 Double-click the table in the model.
The table property sheet appears.
2 Click the Indexes tab.

103
Defining indexes

The Indexes page appears. It lists indexes associated with the table.

3 Click a new line in the list


or
Click the Add a Row tool.
An arrow appears at the beginning of the line.
4 Type an index name and a index code.
5 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.
The index property sheet appears open to the General page.
6 Type or select Index properties.
7 Click the Columns tab.
The Columns page appears. It lists columns associated with the index. At
index creation the list is empty as there are no columns yet associated
with the index.
8 Select the primary key; an alternate key, or foreign key from the
Columns definition dropdown list.
The index is linked to the selected key. The key columns associated with
the index appear in the column list.

104
Chapter 3 Building Physical Data Models

Foreign key names


The foreign keys are represented by the name of the reference that
links the parent and child columns. For example, Refr:sales_title.

9 Select the A checkbox at the end of the column line, if you want index
entries to be in ascending order for that column.
or
Clear the A checkbox at the end of the column line, if you want index
entries to be in descending order for that column.
10 Click OK in each of the dialog boxes.

Removing a column from an index

v To remove a column from an index:


1 Double-click a table in the model.
The table property sheet appears.
2 Click the Indexes tab.
The Indexes page appears. It lists indexes associated with the table.
3 Click an index in the list.
An arrow appears at the beginning of the line.
4 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.
The index property sheet opens to the General page.
5 Click the columns tab.
The Columns page appears. It lists the columns associated with the
index.
6 Select a column in the list of columns.
7 Click the Delete button.
8 Click OK.

105
Defining indexes

Rebuilding indexes
Rebuilding indexes in a PDM automatically updates any changes that you
have made to primary keys, foreign keys, or alternate keys in your model.
You can rebuild indexes for one or more tables in a PDM. You can also
choose to rebuild indexes from the model, or a from a package.
Rebuilding index You can indicate the following parameters to rebuild indexes:
options
Parameters Description
Primary key only When selected, rebuilds primary key indexes. The text
box shows the naming convention for primary keys. By
default this is %TABLE%_PK
Other keys When selected, rebuilds alternate key indexes. The text
box shows the naming convention for alternate keys. By
default this is %AKEY%_AK
Foreign key indexes When selected, rebuilds foreign key indexes. The text
box shows the naming convention for foreign keys. By
default this is %REFR%_FK
Foreign key threshold Minimum number of estimated records in a table that
are necessary before a foreign key index can be created.
The estimated number of records is defined in the
Number box in the table property sheet. If the table has
no specified number of occurrences, the foreign key
indexes are generated by default
Delete and Rebuild When selected all existing indexes are deleted before
index rebuilding
Preserve Indexes When selected, preserves all existing indexes in a PDM.

106
Chapter 3 Building Physical Data Models

Rebuilding indexes from a model

v To rebuild indexes from a global model:


1 Select Tools➤Rebuild Indexes.
The Rebuild Indexes dialog box appears.

2 Select rebuild options.


3 Click the Selection tab.
The Selection page appears.
4 Select the model, for which you want to rebuild indexes, from the
dropdown list at the top of the page.
The tables in the selected model are displayed.
5 Select checkboxes for tables containing indexes to rebuild.
Clear checkboxes for tables containing indexes that you do not want to
rebuild.
6 Click OK.
A message box asks you to confirm the deletion and rebuilding of key
indexes.
7 Click the Yes button.
You return to the current model. All key indexes have been rebuilt.

107
Defining indexes

Rebuilding indexes from a package


You can rebuild indexes from a package.

v To rebuild indexes from a package:


1 From the package, select Tools➤Rebuild Indexes.
The Rebuild Indexes Scope dialog box appears.
2 Select the Rebuild the current package radio button.
3 Click OK.
The Rebuild Indexes dialog box appears.

4 Select, clear or type index options as appropriate.


5 Click OK.

108
Chapter 3 Building Physical Data Models

Deleting an index
There are two ways to delete an index:
♦ Delete an index from the list of indexes
♦ Delete an index from a table

Deleting an index from the list of indexes

v To delete an index from the list of indexes:


1 Select Model➤Indexes.
The list of indexes appears.
2 Click the index to delete from in the list.
An arrow appears at the beginning of the line.
3 Click the Delete button.
4 Click OK.

Deleting an index from a table

v To delete an index from a table:


1 Double-click a table in the model.
The table property sheet appears.
2 Click the Indexes tab.
The Indexes page lists indexes associated with the table.
3 Click the index that you want to delete from the list.
An arrow appears at the beginning of the line.
4 Click the Delete button.
5 Click OK.

109
Defining views

Defining views

A view is an alternative way of looking at the data in one or more tables. It is


made up of a subset of columns from one or more tables.
You define a SQL query for each view.

View properties
The view definition includes the following properties:

Maximum
Property Description length
Name Name for the view 254
Code Code for the view. This code is generated in 254
database scripts
Comment Descriptive label for the view 32Kb
Owner Name of view owner. You choose an owner from a —
list of users. A view can only have one owner at a
time. This is normally the view creator
Usage Group of properties that affect database script —
generation

In addition, you can select any of the following usage properties:

Property Description
Query only Defines view for consultation only. View cannot update
tables
Updateable Defines view for consultation and update. View can update
tables
With check option Implements controls on view insertions
Generate Includes view generation as part of database generation
script

110
Chapter 3 Building Physical Data Models

A view definition also includes the following properties, each with their
respective page:

Property Description
Columns Columns of the view
SQL Query SELECT statements defining the view
Preview SQL preview of view definition

Creating a view
You have two ways to create a view:
♦ Create a view for tables selected in the diagram
♦ Create an empty view then select tables from a list of tables

Creating a view for tables selected in the diagram

v To create a view for tables selected in the diagram:


1 Select one or more tables in the diagram.

Multiple table selection


You can select multiple tables by holding down the SHIFT key while
you select tables in the diagram.

2 Select Tools➤Create View.

111
Defining views

A view symbol appears in the model. It displays all the columns in each
of the tables selected for the view. The names for the tables appear at the
bottom of the view symbol.

3 Double-click the new view symbol.


The view property sheet appears.

4 Type a name and a code for the view.


5 Click OK.

112
Chapter 3 Building Physical Data Models

Creating an empty view then selecting tables

v To create an empty view then select tables:


1 Select Tools➤Create View.
A selection box appears. It lists all the tables available in the model.

2 Select checkboxes for tables that you want to be included in the view.
3 Click OK.
A view symbol appears in the model. It displays all the columns in each
of the tables selected for the view. The names for the tables appear at the
bottom of the view symbol.

113
Defining views

4 Double-click the new view symbol.


The view property sheet appears.
5 Type a name and a code for the view.
6 Click OK.

Modifying view properties


There are two approaches to modifying view properties:
♦ Modify a view property sheet
♦ Modify an entry in the list of views

Modifying a view from its property sheet


The View property sheet displays view definitions that you can modify.

v To modify view properties from its property sheet:


1 Double-click a view in the model.
The view property sheet appears.
2 Type or select modifications to the view properties.
3 Click OK
or
Click another tab to modify any additional view property.

Modifying a view from the list


The list of views includes all views attached to the current model. You can
modify certain view properties from the list.

v To modify view properties from the list:


1 Select Model➤Views.
The list of views appears.
2 Click the view to modify.
An arrow appears at the beginning of the line.
3 Type or select modifications to the properties displayed for the view.

114
Chapter 3 Building Physical Data Models

Properties displayed in a list


The properties that are displayed in a list are determined by the list
filter. To add or remove properties from a list, click the Customize
Columns and Filters, and select or clear the appropriate property
checkboxes.

4 Click OK.
or
Click a different view in the list.

Defining a query for a view


You define queries for a view from the SQL Query page of the view property
sheet. Each SELECT query is shown in the Query dropdown listbox. The
definition for the selected query appears in the textbox.
Selecting tables, You can add tables, columns and references to the view from the property
columns, and sheet for each query. You can access the query property sheet by clicking the
references for a Properties tool shown below from the tool bar
view

Based on your selection of tables, columns, and references, PowerDesigner


generates a query in SQL syntax.
The resulting query uses FROM statements for tables and WHERE
statements for columns linked by joins in a reference.
Creating a query in You can also construct a query using an SQL editor. You can open the SQL
an editor editor by clicking the Edit tool shown below from the tool bar.

Selecting a table or columns for a view

v To select a table for a view:


1 Double-click a view in the diagram.
The view property sheet appears.
2 Click the SQL Query tab.

115
Defining views

The SQL Query page appears. It shows each SELECT query in the
Query dropdown listbox. The text for the query appears in the textbox.

3 Select a query from the Query dropdown listbox. This is the query that
contains the SELECT statement to which you want to add a table.
4 Click the Properties tool from the tool bar at the top of the page.

The property sheet for the SELECT query appears. The query definition
is shown in the textbox.
5 Click the Tables tab if you want to add a table to the view.
or
Click the Columns tab if you want to add columns to the view.
The Tables or Columns page appears. It lists the tables or columns
currently included in the SELECT statement.
6 Click the Add a Row tool.
Click the new line in the list.
or
Click a new line in the list.

116
Chapter 3 Building Physical Data Models

A dropdown list appears. It lists all the available tables in the model, or
all the available columns for the tables currently defined for the view.

7 Select a table name.


or
Select a column name.
The table name, or column name, is added to the list.

Adding multiple tables or columns


You can add multiple tables or columns to a view by clicking a new
line in the list for each table or column that you want to add, and
selecting the appropriate table or column from the dropdown list.

8 Click OK.
You return to the SQL query page. The table and all of its columns, or
the selected new columns, are added to the SELECT statement. If you
select tables that share a reference link, the reference is automatically
added in a WHERE clause to the query.
9 Click OK.
The new table and columns appear in the view symbol.

117
Defining views

Selecting a reference for a view

v To select a reference for a view:


1 Double-click a view in the diagram.
The view property sheet appears.
2 Click the SQL Query tab.
The SQL Query page appears. It shows each SELECT query in the
Query dropdown listbox. The text for a selected query appears in the
textbox.
3 Select a query from the Query dropdown listbox. This is the query that
contains the SELECT statement to which you want to add a table.
4 Click the Properties tool from the tool bar at the top of the page.

The property sheet for the SELECT query appears. The query definition
is shown in the textbox.
5 Click the Where tab.

118
Chapter 3 Building Physical Data Models

The Where page appears. It shows the SQL expression for the parent
table column and the child table column that are linked by the =
operator.

6 Click the Add a Row tool.


Click in the first Expression column on the new line in the list.
or
Click in the first Expression column on a new line in the list.

119
Defining views

A dropdown list appears. It lists all the available columns in the tables
defined for the view.

7 Select a column.
Click in the Operator column for the same line.
A dropdown listbox appears listing SQL operators.
8 Select the = operator.
Click in the second Expression column for the same line.
A dropdown listbox appears listing available columns.
Select a column.
9 Click OK.
10 You return to the SQL Query page. The new reference is added to the
WHERE clause.

Assigning an alias to a table or a column


You can assign an alias to a table or a column. You use this alias in the query
script instead of typing out the full code.

v To assign an alias to a table or a column:


1 Double-click a view symbol in the diagram.

120
Chapter 3 Building Physical Data Models

The view property sheet appears.


2 Click the SQL Query tab.
The SQL Query page appears. It shows each SELECT query in the
Query dropdown listbox. The text for a selected query appears in the
textbox.
3 Select a query from the Query dropdown listbox. This is the query that
contains the SELECT statement to which you want to add an alias to a
table or a column.
4 Click the Properties tool from the tool bar at the top of the page.

The property sheet for the SELECT query appears. The query definition
is shown in the textbox.
5 Click the Tables tab.
or
Click the Columns tab.
The Table or Columns page appears.
6 Click the number at the start of the line for the table or column to which
you want to assign an alias.
An arrow appears at the start of the line, and the line is highlighted.
7 Click the Alias column for the same line.
8 Type an alias in the Alias column.
9 Click OK in each of the dialog boxes.

Inserting clauses in a query


You can add the following types of clauses to a query:

SQL clause Description


WHERE Specify search conditions
GROUP BY Divides rows into groups based on values in the columns
HAVING Specify grouping conditions
ORDER BY Sort query results by one or more columns

121
Defining views

Using the SQL page


You can view the clauses that are inserted in the query from the SQL page of
the query property sheet. You can also edit the query manually from this
page.

Inserting a WHERE clause in a query

v To insert a WHERE clause in a query:


1 From the Query property sheet, click the Where tab.
The Where page appears.
2 Click the Add a Row tool.
Click in the first Expression column for the new line in the list.
or
Click in the first Expression column for a new line in the list.
A down arrowhead appears.
3 Click the down arrowhead.
A dropdown listbox appears. It lists all the available columns in the
tables defined for the view.
4 Select a column.
Click in the Operator column for the same line.
A dropdown listbox appears listing SQL operators.
5 Select an operator.
Click in the second Expression column for the same line.
A dropdown listbox appears listing available columns.

Expression column is not visible


You can make the second Expression column visible, by clicking the
Customize Columns and Filter tool from the tool bar at the top of the
page. From the selection box that appears, select the Expression
checkbox and click OK.

6 Select a column.
7 Type a prefix in the Prefix column.
Type a suffix in the Suffix column.
8 Click OK.

122
Chapter 3 Building Physical Data Models

Inserting a GROUP BY clause in a query

v To insert a GROUP BY clause in a query:


1 From the Query property sheet, click the Group By tab.
The Group By page appears.
2 Click the Add a Row tool.
Click the new line in the list.
or
Click a new line in the list.
A down arrowhead appears at the end of the line.
3 Click the down arrowhead.
A dropdown list appears. It lists all the available columns in the tables
defined for the view.
4 Select a column.
The Column name appears in the list.

Customizing an expression
You can customize a column expression by clicking the Ellipsis
button next to the down arrowhead. An SQL Editor appears. Type an
expression in the textbox and click OK. The new expression appears
in the column list.

5 Click OK.
The selected columns appear in a GROUP BY clause in the textbox
containing the SQL statement in the SQL Query page.

Inserting a HAVING clause in a query

v To insert a HAVING clause in a query:


1 From the Query property sheet, click the Having tab.
The Having page appears.
2 Click the Add a Row tool.
Click in the first Expression column for the new line in the list.
or
Click in the first Expression column for a new line in the list.

123
Defining views

A down arrowhead appears.


3 Click the down arrowhead.
A dropdown listbox appears. It lists all the available columns in the
tables defined for the view.

Customizing an expression
You can customize an expression by clicking the Ellipsis button next
to the down arrowhead. An SQL Editor appears. Type an expression
in the textbox and click OK. The new expression appears in the
Expression column.

4 Select a column.
Click in the Operator column for the same line.
A dropdown listbox appears listing SQL operators.
5 Select an operator.
Click in the second Expression column for the same line.
A dropdown listbox appears listing available columns.

Expression column is not visible


You can make the second Expression column visible, by clicking the
Customize Columns and Filter tool from the tool bar at the top of the
page. From the selection box that appears, select the Expression
checkbox and click OK.

6 Select a column.
7 Type a prefix in the Prefix column.
Type a suffix in the Suffix column.
8 Click OK.

Inserting an ORDER BY clause in a query

v To insert an ORDER BY clause in a query:


1 From the Query property sheet, click the Order By tab.
The Order By page appears.
2 Click the Add a Row tool.
Click the new line in the list.
or

124
Chapter 3 Building Physical Data Models

Click a new line in the list.


A down arrowhead appears at the end of the line.
3 Click the down arrowhead.
A dropdown list appears. It lists all the available columns in the tables
defined for the view.
4 Select a column.
The Column name appears in the list.

Customizing an expression
You can customize a column expression by clicking the Ellipsis
button next to the down arrowhead. An SQL Editor appears. Type an
expression in the textbox and click OK. The new expression appears
in the column list.

5 Click OK.
The selected columns appear in an ORDER BY clause in the textbox
containing the SQL statement in the SQL Query page.

Displaying query syntax


You can display each query that PowerDesigner will generate based on the
view definition.

v To display query syntax:


1 Double-click a view symbol.
The view property sheet appears.
2 Click the SQL Query tab.
The SQL Query page displays the syntax of each query that
PowerDesigner generates based on your view definition.
3 Select a SELECT statement from the Query dropdown listbox.
The query definition is displayed in the textbox.
4 Click OK.

125
Defining views

Editing a query
You can use editing features in the SQL Editor to edit a query.

v To edit a query using the SQL Editor:


1 Double-click a view.
The view property sheet appears.
2 Click the SQL Query tab.
The SQL Query page appears.
3 Click the Edit tool.

The SQL Editor appears. It displays the SQL query in the textbox. The
category of objects that you can add to the query are listed in the box to
the top left, and the individual objects that you can add within each
category are listed in the center box.

4 Click the position in the definition textbox where you want to insert the
SQL script for an object.
5 Select a category from the top left box.
For example, select Tables to display the list of available tables. The list
of available objects in that category appear in the middle box.
6 Double-click the item that you want to add to the script.
or

126
Chapter 3 Building Physical Data Models

Select a function or an operator to add to the script from the Function or


Operator dropdown list respectively.
The item is added to the script.
7 Click OK in each of the dialog boxes.

Displaying text in view symbols


You can display the following text in a view symbol:

Text display
preference When selected, what it displays
Columns All columns in the view, an asterisk (*) for multiple column
selection, or a defined number (limit) of columns depending on
the selections listed below*
*All columns All columns in the view. Multiple column selection is represented
by an asterix (*)
*No formulas All columns in view including multiple column selection
*Limit (x) Number of columns depending on defined value of x
Tables Tables in the view
Owner Name of view owner
Name Column name specific to the view
Expression SQL expression for each column
Data types Data type for each column

v To display text in a view symbol:


1 Select Tools➤Display Preferences.
or
Right-click the diagram background and select Display Preferences from
the context menu.
The Display Preferences dialog box opens to the General page.
2 Click the View node under the Object View node in the Category tree
view.
The View page appears.
3 Select or clear checkboxes in the View groupbox and View Columns
groupbox.

127
Defining views

Default options
Click the Default button to display default View display preferences.
Click the Set As Default button to set current display preferences as
default selections.

4 Click OK.

128
Chapter 3 Building Physical Data Models

Defining check parameters


Check parameters are set of conditions which data must satisfy to remain
valid.
There are three types of check parameters:

Can be
Parameter type Description attached to
Standard check Common data constraints which define a Columns
parameters data range. For example minimum and Domains
maximum values for a column
Additional check SQL expression defining a data Columns
parameters constraint using the %MINMAX%, Domains
%LISTVAL%, and %RULES% variables
that are instantiated with standard
parameter values
Validation rule Business rule that is defined as a server Tables
expression, and is attached to one of the Columns
following listed objects Domains

Setting standard check parameters for objects

Standard parameters indicate common data constraints. The following table


lists standard parameters:

Parameter Description
Minimum Lowest acceptable numeric value
Maximum Highest acceptable numeric value
Default Value assigned in absence of an expressly entered value
Unit Standard measure
Format Data format (for example, 9999.99)
Lowercase Forces all alphabetical characters to lowercase
Uppercase Forces all alphabetical characters to uppercase
Cannot Modify Protects from changes, results in a non-modifiable column in
the table when generated in the database

129
Defining check parameters

Parameter Description
List of Values Authorized values
Label String that identifies an authorized value in the list

v To set standard parameters:


1 Select Model➤Domains.
or
Select Model➤Columns.
The List of Domains or List of Columns appears.
2 Click a domain in the list.
or
Click a column in the list.
An arrow appears at the beginning of the line.
3 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.
The property sheet for the domain or column appears.
4 Click the Standard Checks tab.
The Standard Checks page appears.

130
Chapter 3 Building Physical Data Models

5 Type your choice of Standard Parameters.


6 Click OK.

Defining additional check parameters for objects


You can write an SQL statement using the following standard variables
defined as standard check parameters and validation rules:

Variable Description
%MINMAX% Minimum and maximum values defined in Values groupbox on
Standard Checks page
%LISTVAL% Customized values defined in List Values groupbox on
Standard Checks page
%RULES% Validation rule expression defined on Expression page of the
Rules property sheet

You define additional check parameters for data constraints where standard
check parameters are not sufficient.
Example A table in a data model for a clothing shop may contain check parameters
defined for a column SIZE, which depend on the check parameters defined
on another column CLOTHING TYPE, as clothing size for a skirt in one
country may be different from the same size in another country.
In this case an expression is required to create a constraint which uses check
parameters defined for both columns.

v To define additional check parameters:


1 Select Model➤Domains.
or
Select Model➤Columns.
The List of Domains or List of Columns appears.
2 Click a domain in the list.
or
Click a column in the list.
An arrow appears at the beginning of the line.
3 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.

131
Defining check parameters

The property sheet for the domain or column appears.


4 Click the Additional Checks tab.
The Additional Checks page appears.

5 Type SQL expression using the variables %MINMAX%, %LISTVAL%,


and %RULES%.
6 Click OK.

Using a validation rule in check parameters


A validation rule is a rule that validates data based on a corresponding
business rule. A validation rule can be generated as a check parameter when
the following conditions apply:
♦ Validation rule is attached to a table, column, or domain
♦ Validation rule is defined as a server expression
At generation, validation rule variables are instantiated with the following
values:

Variable Value
%COLUMN% Code of the column to which the business rule applies
%DOMAIN% Code of the domain to which the business rule applies

132
Chapter 3 Building Physical Data Models

Variable Value
%TABLE% Code of the table to which the business rule applies
%MINMAX% Minimum and maximum values for the column or domain
%LISTVAL% List values for the column or domain
%RULES% Server validation rules for the column or domain

$ For more information on defining business rules, see the chapter Using
Business Rules.

v To use a validation rule in check parameters:


1 Select Model➤Tables.
or
Select Model➤Domains.
or
Select Model➤Columns.
The List of Tables, or List of Domains or List of Columns appears.
2 Click a table in the list.
or
Click a domain in the list.
or
Click a column in the list.
An arrow appears at the beginning of the line.
3 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.
A property sheet appears.
4 Click the Rules tab.
The Rules page appears.
5 Click the Add button.
A list appears displaying the available business rules in the model.
6 Select a business rule in the list.
7 Click OK in each of the dialog boxes.

133
Defining check parameters

Validation rule expressions


You must click the Rules button to modify the expression attached to
a validation rule. You can also modify validation rule expressions
from the list of business rules, by clicking the Define button.

Managing quotation marks around values


For a domain or a column, standard parameters can indicate minimum,
maximum, and default values as well as a lists of values.
In general, if the data type of domain or column is a string data type,
quotation marks surround its values in the generated script. The generation of
single or double quotation marks depends on the target DBMS.
However, quotation marks are not generated in the following cases:
♦ You define a data type that is not recognized as a string data type by
PowerDesigner
♦ Value is surrounded by tilde characters
♦ Value is a keyword defined in the DEF file (for example, NULL)
In addition, if the value is already surrounded by quotation marks additional
quotation marks are not generated.
The following table shows the way a value for a string data type is generated
in a script:

Value for string data type Result in script


Active ’Active’
’Active’ ’Active’
"Active" ’"Active"’
˜Active˜ Active
NULL NULL

134
Chapter 3 Building Physical Data Models

Defining physical options


Depending on the current DBMS, you can assign values to physical options
for tables, indexes, tablespaces, storages, primary keys, and alternate keys.
Physical options are not supported for certain databases.
You define physical options in the Options page which is accessible from the
property sheet for an object. The Options page has two panes. The left pane
contains the syntax for the physical options available. The right pane contains
the physical options that have been selected for the object. You use the
following tools to add physical options to, or remove from, the current
object:

Tool Action when clicked


Adds physical option selected in Syntax page (left pane) to Items page
(right pane)
Aligns a selected physical option in the Items page with the
corresponding physical option in the Syntax page
Removes physical option selected in Items page

$ For information on changing the current database, see the chapter


Database Creation and Modification.
DBMS syntax The syntax for a physical option also depends on the DBMS. The Options
page displays the syntax that is recognized by the current DBMS. The
following is an example of a syntactical difference for the tablespace option
in different DBMS:

DBMS Tablespace option syntax


Oracle 6.0 or higher tablespace
Sybase Adaptive Server in
Anywhere

135
Defining physical options

Tablespace and You can choose a tablespace or storage already defined in the model as a
storage options value for a tablespace or storage that you define for a table. These are listed
in a dropdown listbox at the bottom of the Options page when you choose to
add a tablespace or storage for a table.

$ For more information on defining tablespaces and storages, see the


section Configuring tablespace and storage in the chapter Database Creation
and Modification.
Defining default Default values for physical options are defined in the DefOptions field for the
physical options appropriate PDM object in the current DBMS. If you want new default
values for physical options to apply to all models using a DBMS, you need to
modify the DBMS in Link mode. If you assign values to a DBMS in Local to
the Model mode, the default values apply only to the current model.
$ For information on using the DBMS Definition Editor to edit a DBMS
definition, see the chapter DBMS Definition Editor.
Generating default The values you assign for physical options can be included in a database
values creation script that you generate from a PDM, or can be directly generated in
the target database via ODBC. You select the appropriate physical option
from the Selection page of the Database Generation dialog box.
You can view the script for a physical option in the Preview page for the
object for which it is defined.
Physical option default values can also be reverse engineered from a database
into a PDM.

136
Chapter 3 Building Physical Data Models

v To define default physical options:


1 Open the property sheet for the object to which you want to assign a
physical option value.
2 Click the Options tab.
The Options page appears. The syntax page in the left pane lists the
database options available. These options are DBMS specific. The
Options page that appears below shows the physical options available for
IBM DB2 UDB 5.X Common Server.

3 Select an option from the options listed on the Syntax page in the left
pane.
4 Click the Add tool.
The name of the option appears on the Items page in the right pane
5 Select the option in the Items page in the right pane.

137
Defining physical options

The option name appears with an equals sign next to a text box at the
bottom of the dialog box. Depending on the type of value the option can
take, a dropdown listbox can appear instead of a text box.

6 Type a value for the option in the text box below the right pane
or
Select a value from the dropdown listbox below the right pane.
7 Click OK.

138
C H A P T E R 4

Managing Physical Data Models

About this chapter This chapter describes how to manage objects in a Physical Data Model
(PDM) with users and object owners. It also describes checking the validity
of a PDM, retrieving multidimensional objects used in a WarehouseArchitect
Model (WAM), importing an ERwin model.
Contents
Topic Page

Managing users and owners 140


Checking a PDM 143
Retrieving multidimensional objects 153
Importing an ERwin model into a PDM 154
Exporting a PowerDesigner 7 model to PowerDesigner 6 156

139
Managing users and owners

Managing users and owners

The user is a name that identifies a person or group working with objects in a
PDM, which has the ability to own other objects in the PDM. You can create
a user and then attach the user to an object.
Owners When a user is attached to an object, it becomes the owner of that object.
Each object can only have one owner at a time. Only an object owner has the
right to modify the object. In a PDM, you use the owner relationship to help
to organize and keep track of modifications to objects in the model.
Example When you create a table, by default the object has no owner. You can select
your user name from a list of users, and attach it to the table. You then
become the table’s owner.
Owners for tables In a PDM, the following objects can have owners:
views, procedures
♦ Tables
and functions
♦ Views
Each table or view in a PDM, can have only one owner at a time.
You can also attach a user to a procedure or function.
Owner uses You can use object owners for the following purposes:

Purpose Description
Managing object In a model where many users have access to the same
modifications in a objects, you can control object modifications by attaching
PDM owners to objects
Generating a In a model where many users have access to the same
database for owner objects, you can generate a database only for the objects
specific objects that belong to a particular owner

140
Chapter 4 Managing Physical Data Models

Creating a user
You need to create a user before you can attach that user to an object.

v To create a user:
1 Select Model➤Users.
The List of Users appears.
2 Click a blank line in the list.
or
Click the Add a Row tool.
An arrow appears at the beginning of the line.
3 Type a user name and a user code.
4 Click OK.

Attaching an object to a user


You can attach a user to one or more objects in a PDM. When you attach a
user to an object, the user becomes the owner of that object. You can attach a
user to the following objects:
♦ Tables
♦ Views

v To attach an object to a user:


1 Double-click a table in the diagram.
or
Double-click a view in the diagram.
The object property sheet appears.
2 Click the down arrow at the end of the Owner dropdown listbox.
A dropdown list appears. It displays all the users defined in the model.
3 Select a user from the dropdown list.
The user name appears in the Owner dropdown listbox.

141
Managing users and owners

Accessing the List of Users from an object property sheet


You can access the List of Users from the property sheet for a table or
a view by clicking the Ellipsis button at the end of the Owner
dropdown listbox.

4 Click OK.

142
Chapter 4 Managing Physical Data Models

Checking a PDM
You can use the Check Model to check the validity of a PDM at any time.
The following general rules apply to PDM:
♦ Each object name must be unique
♦ Model constraints must be compatible with database constraints
♦ Each table must have at least one column
♦ Each index must have a column
♦ Each reference must have at least one column pair
The procedure that generates a database starts by checking the validity of the
PDM. If an error is found, the database (or database generation script) is not
generated.

143
Checking a PDM

Object parameters verified by Check model


The Check Model verifies the validity of the following objects in a PDM:

Object Parameter
Package Circular references
Constraint name uniqueness
Tables Table name and code uniqueness and length
Existence of key, index, column, and reference
Number of auto-incremented columns
Domains and Domain name and code uniqueness and length
columns Incoherent default values and validation rules
Data type precision and definition
Column and domain divergence
Indexes Index name and code uniqueness and length
Existence and numbers of index columns
Multiple clustered and identical indexes
Unidentified PK,AK,FK indexes
Key consistency
Divergence from cluster status
Primary and alternate Key name and code uniqueness
keys Key code length
Keys without, with too many, and with identical columns
References Reference and constraint code uniqueness
Reference code length
Circular dependency
Existence of reference joins
Declarative referential integrity constraints
Default integrity options
FK data type, business rule definition divergence from
relevant key column definition
Views View name and code uniqueness and length
Incomplete query
Users User name and code uniqueness
User code length
Triggers Trigger code length
Procedures Procedure code length

144
Chapter 4 Managing Physical Data Models

PDM check options


When you check a PDM, you can choose to indicate levels of severity for
problem that the check model encounters, and to also have certain problems
automatically corrected.
Levels of problem You can set a level of problem severity for each object parameter that is
severity verified by the Check model. This severity level can depend on the degree of
normalization that you want to achieve in a your model.
When you check a PDM, if a parameter is found to be invalid, it can be
displayed with one of two types of messages, depending on the degree of
problem severity you have assigned to that parameter:

Message Description
Error Major problem that impedes database generation
Warning Minor problem or recommendation

Automatic You can choose to have certain problems corrected automatically by


correction PowerDesigner. For example, if a column code length is longer than the
length specified in the MaxColumnLen field in the DBMS, then
PowerDesigner can automatically truncate the code to within the defined
length.
This option is not available for all object parameters. All problems that can
not be corrected automatically , must be corrected manually. For example
PowerDesigner will not create a column for an existing index. You need to
create the appropriate column from an object property sheet.

145
Checking a PDM

Indicating error You can use the following tools from the Check Model Parameters dialog
severity box to indicate either an error or warning level of problem severity, and also
if you want PowerDesigner to automatically correct an error:

Tool Indicates Description


Error Major problem that impedes database generation

Warning Minor problem or recommendation

Automatic Indicates that PowerDesigner will correct the


correction problem automatically

Object selection in the Check Model


You select objects for verification by the Check Model from the Selection
page.
Listing objects You can list for selection, objects in the current model, or objects in
contained in a individual packages contained in the model.
model or package
You can list all objects in the current model, or a package, by selecting the
Include Sub-packages tool.
You have the following selection options:

Include Sub-
Parent object packages Displays
Model Selected All objects in model including all objects
contained in packages and sub-packages
Model Not selected All objects in model except objects
contained in packages and sub-packages
Package Selected All objects contained in package including
all objects contained in sub-packages
Package Not selected All objects in package except objects
contained in sub-packages

Objects selected in the diagram


Graphically selected objects in your diagram can be automatically selected
for verification by the Check Model by clicking the Use Graphical
Selection tool in the Selection page tool bar.

146
Chapter 4 Managing Physical Data Models

Checking a global PDM

v To check a global PDM:


1 Select Tools➤Check Model.
or
Right-click the diagram background and select Check Model from the
context menu.
The Check Model Parameters dialog box opens to the Options page.
2 Expand an object parameter node.
The object parameters which are verified by the Check Model are
displayed with the symbols indicating a degree of problem severity.

3 If you want to change a degree of problem severity, select the object


parameter and then select either the Error or Warning tool.
The symbol changes to the appropriate severity level.
4 If you want PowerDesigner to automatically correct a problem, select the
object parameter and then select the Automatic Correction tool.
The Automatic Correction symbol appears superimposed on the Error or
Warning symbol for that object parameter.
5 Click the Selection tab.

147
Checking a PDM

The Selection page appears.

6 Select a model from the dropdown list at the top of the dialog box.
7 Click an object tab.
The corresponding object page displays all the objects in the current
PDM.
8 Select checkboxes for objects that you want to be checked.
Clear checkboxes for objects that you do not want to be checked.

Selecting all or clearing all checkboxes


You can select all object checkboxes by click the Select All tool.
You can clear all object checkboxes by clicking the Deselect All tool.

9 Click OK.

148
Chapter 4 Managing Physical Data Models

The Check Model Result List displays errors and warnings based on
your choice of check options.

Dockable result window


When you right click an object parameter a menu appears listing
correction options. Among these, you can also select options to clear,
dock or hide the result window.

Displaying previously applied check options


If you click the Apply button in the Check Model Parameters dialog box, all
error and warning selections are stored in memory.

v To display errors and warnings selected in the last check:


♦ Select Tools➤Check Model.
The Check Model Parameters dialog box opens to the Options page. The
object parameters are displayed with the Error or Warning icons selected
in the last check.

149
Checking a PDM

Making corrections based on PDM check results


You can use the Check Model to locate and correct problems in the PDM.
You can choose one of the following correction options from the Check
toolbar:

Symbol Option Description


Manual correction Displays property sheet of problem object

Check detail Displays description of the error and suggestion


for correction
Recheck Checks selected object parameter, normally
after a correction has been done
Automatic Automatically corrects certain errors
correction

Navigating in the The Check tool bar also contains navigation tools that you can use to move to
error list the first, previous, next, or last errors that are listed. You can also navigate in
the list of errors by right-clicking an object parameter and selecting Go To
First error, Previous error, Next error, or Last error from the context menu.

Right click menu


When you right click an object parameter a menu appears listing the
correction options Manual Correction, Check Detail, Recheck, and
Automatic Correction. You can also select options to clear, dock and hide
the result window.

150
Chapter 4 Managing Physical Data Models

Automatic Automatic correction fixes the following types of errors and warnings:
correction
♦ Inappropriate foreign key columns
♦ Non-unique names
♦ Code too long for target database (if you select Database Constraints)
♦ Inappropriate primary keys, foreign keys, and unique indexes
♦ Divergence in domain values, check parameters, and validation rules for
auto-migrated foreign keys

Divergence in auto-migrated foreign keys


Divergence in domain values, check parameters, and validation rules
for an auto-migrated foreign key, are only corrected if you have
selected the corresponding auto-migrate options in Model options

You must always correct other errors manually.

Making manual corrections to a PDM

v To make manual corrections to a PDM:


1 From the Result List, select an object parameter.
2 Right-click the object parameter and select Correct from the contextual
menu.
The object property sheet appears.
3 Select the appropriate tab and make the necessary correction.
4 Close the property sheet.
5 Re-select the object parameter.
6 Right-click the object parameter and select Re-check from the contextual
menu.
Verify that the problem has been corrected.

151
Checking a PDM

Making automatic corrections to a PDM

v To make automatic corrections to a PDM:


1 From the Result List, select an object parameter.
2 Right-click the object parameter and select Auto-Correction from the
contextual menu.
3 Right-click the object parameter and select Re-check from the contextual
menu.
Verify that the problem has been corrected.

152
Chapter 4 Managing Physical Data Models

Retrieving multidimensional objects


Tables can be displayed as Fact or Dimension tables in the display of a
diagram. These types of tables are used in the PowerDesigner
WarehouseArchitect model. Selected PDM table symbols can be transformed
into Fact and Dimension table symbols as follows:
♦ Child tables become Fact tables
♦ Parent tables become Dimension tables
The new table type is indicated in the Type dropdown listbox in the table
property sheet.

Opening a WAM
You can open a version 6 WarehouseArchitect Model (WAM) in
PowerDesigner. To do so, select File ➤ Open, and type *.wam in the File
Name box. Select a model from the list of existing models that appears,
and click OK. The WAM is converted into a PDM.

v To retrieve multidimensional objects:


1 Select Tools➤Retrieve Multidimensional Objects.
A selection box appears.
2 Select table checkboxes for tables that you want to define as
multidimensional.
or
Clear table checkboxes for tables that you do not want to define as
multidimensional.
3 Click OK.
The selected table symbols are indicated with the appropriate
multidimensional icon in the top left corner of each table symbol.

153
Importing an ERwin model into a PDM

Importing an ERwin model into a PDM


You can import a model built with ERwin into a PDM.
The import process translates ERwin objects into PDM objects as follows:

Object in an ERwin model Imported object in a PDM


Main subject area Model
Stored display and subject area Diagram
Business rule Business rule
Domain Domain
Column Column
Key Key
Table Table
Relationship Reference
Referential integrity Referential integrity
Index Index
View table View
View relationship Alias table
Fact, dimension, outrigger Table
Target database Current DBMS
Valid value Check parameter
Tablespace Tablespace
Segment Storage
Symbols (including size and position) Symbols (including size and position)
Description Description
Annotation Annotation
Color (pen and background) Color (pen and background)
Text block Text symbol

You cannot import ERwin triggers and stored procedures, Erwin rules, Erwin
user-defined properties, ERwin reports, or ER1 files. Text color and fonts are
also not imported. If you are using ERwin/SQL, generate a database from
your ER1 file and then reverse engineer that database into a PDM.

154
Chapter 4 Managing Physical Data Models

v To import an ERwin model:


1 Select File➤Open.
An open file dialog box appears.
2 Select or browse to the directory that contains the ERwin file.
3 Select Erwin Model (*.erx) file from the Files of Type dropdown listbox.
The available ERwin files are listed.
4 Select a file.
5 Click Open.
A message box displays the available import formats.

6 Select a format.
7 Click OK.
A progress box shows the progress rate of the import process. At the end
of the import process, the model appears in the diagram.

155
Exporting a PowerDesigner 7 model to PowerDesigner 6

Exporting a PowerDesigner 7 model to


PowerDesigner 6
When you export a PowerDesigner 7 model to PowerDesigner 6, you save
your PD7 model under the version 6 format.
Exporting a PowerDesigner 7 model to PowerDesigner 6 should only be used
to recover information of the PD7 model to work with PD6 models.
You should not reexport a PD6 model to PD7.
The following PowerDesigner 7 objects are exported to PowerDesigner 6:
♦ Tables
♦ Columns
♦ Primary keys
♦ Domains
♦ Views
♦ References
The following objects are either transformed or lost when exported to
PowerDesigner 6:
Packages Packages in PowerDesigner 7 are not exported to version 6. Objects
contained in packages are generated as objects of the global model in version
6. All package properties are lost after an export to version 6.
Namespace All objects contained in a package which do not use the parent namespace,
have their names and codes prefixed by the full path of the package when
exported to version 6.
All other objects keep their names and codes which are already unique in the
model when exported to version 6.
Shortcuts When a PowerDesigner 7 model is exported to PowerDesigner version 6,
shortcuts are generated as follows:

Shortcut In PowerDesigner 6 the shortcut is…


Internal Generated as objects belonging to the global model and reused by
several sub-models
External Not generated. All links between external shortcuts are also not
generated

156
Chapter 4 Managing Physical Data Models

v To export a PowerDesigner 7 model to version 6:


1 Select File➤Save As.
The Save As dialog box appears.
2 Browse to the directory where you want to save the model.
3 Select Limited PDM Version 6 from the Save As Type dropdown
listbox.
4 Click Save.

157
Exporting a PowerDesigner 7 model to PowerDesigner 6

158
C H A P T E R 5

Reverse Engineering

About this chapter This chapter describes how you can reverse engineer database objects to a
PDM.
Contents
Topic Page

Reverse engineering a database schema 160


Generating a PDM from a database 161
Generating a PDM from a database creation script 166

159
Reverse engineering a database schema

Reverse engineering a database schema


Reverse engineering is the process of generating a PDM, or specific PDM
objects, from an existing database schema.
There are two ways to generate a PDM from a database schema:

Generate PDM
using Description
Script file You reverse engineer an SQL script which contains creation
statements. This is normally the script used to generate the
database
ODBC data source You reverse engineer the schema for an existing database,
specifying an ODBC data source, and connection
information

160
Chapter 5 Reverse Engineering

Generating a PDM from a database


When you reverse engineer a database schema using an ODBC data source,
you can choose to generate a PDM for all objects, or selected objects, in the
database.
The object types that you can reverse engineer are DBMS-dependant.
Unavailable object types do not appear for selection.
Object types for Using an ODBC data source, you can select the following object types for
reverse reverse engineering:
engineering
Tables
Views
System tables
Synonyms
Users
Domains
Triggers
Procedures
Tablespaces and storages

Reverse engineering users


Only users that have creation rights are reversed engineered.

User-defined and You can reverse engineer user defined and abstract datatypes. In the
abstract data types generated PDM, the names of these data types appear in the List of Abstract
Data Types.

Filters and options for reverse engineering


You can use filters to restrict the number of objects to reverse engineer.
Certain object types have attributes, or options, that you can select to be
included in the generated PDM.
Filters You can restrict database objects to reverse engineer by selecting an owner or
a database qualifier.
The following filters are available:

161
Generating a PDM from a database

Filter Description
Qualifier A qualifier is a database or partition in a database that contains one
or more tables. When a qualifier is selected as a filter, it restricts the
objects available for reverse engineering to the objects contained
within the selected qualifier
Owner Normally the creator of a database object is its owner. When Owner
is selected as a filter; it restricts the objects available for reverse
engineering to the objects owned by the selected owner

Selecting objects from multiple owners


To reverse engineer objects from multiple owners, you can select All as a
filter from the Owner dropdown listbox. All the objects belonging to all
owners appear in the list, and you can select the objects for reverse
engineering regardless of their owner.

Reverse options Reverse engineering options are dependant on object type, and the selected
DBMS. To display, or modify, the reverse engineering options for an object
type, you click the appropriate page tab in the ODBC Reverse engineering
dialog box. Unavailable options appear grayed.
You can select reverse engineering options for the following object types:

Object type Option


Table Indexes
Checks
Physical options
Primary keys
Foreign keys
Alternate keys
View Reverse as table

Reverse engineering database objects to a PDM


You can reverse engineer objects to a new PDM, or you can add objects to an
existing PDM.
Merging two PDM When you reverse engineer database objects into an existing PDM, a model
merge window appears after the reverse engineering process is complete.
You can then use the model merge function to integrate the reversed objects
into a current model.

162
Chapter 5 Reverse Engineering

Automatic When you merge database objects that have been reverse engineered into a
archiving current PDM, you can choose to archive the newly generated PDM, by
selecting the Automatic Archive checkbox from the model merge window.
$ For more information on comparing and merging two models, see the
chapter Comparing and Merging Models in the PowerDesigner General
Features Guide.

v To reverse engineer database objects to a PDM:


1 Select Database➤Reverse Engineering.
The Reverse Engineering a Database dialog box appears.

2 Click the Using An ODBC Data Source radio button.


3 Click the Connect to an ODBC Data Source button at the end of the
Using An ODBC Data Source box.
A dialog box asks you to identify a data source and connection
parameters.

4 Select the Machine Data Source radio button.

163
Generating a PDM from a database

Select a machine data source from the dropdown listbox.


or
Select the File Data Source radio button.
Browse to and select a file data source.
You can add a data source by clicking the Add button and selecting
Setup configuration parameters.
$ For information on configuring a data source, see the chapter
Database Creation and Modification.
5 Type your user ID and password.
6 Click Connect, and if prompted by your data source, enter additional
connection parameters.
The Reverse Engineering a Database dialog box reappears. The Script
file, or ODBC data source, that you have selected appears in the
appropriate box.
7 Click OK.
The ODBC Reverse Engineering dialog box appears.

8 Select a filter for Qualifier and Owner in the dropdown listboxes at the
top of the dialog box.
9 Click an object type tab.
Select checkboxes for objects to reverse engineer.
Clear checkboxes for objects that you do not want to reverse engineer.
Select or clear checkboxes for options where they are available for each
object type.

164
Chapter 5 Reverse Engineering

Selecting or clearing all object checkboxes


You can select all object check boxes for an object type
by selecting the Select All tool.
You can clear all object checkboxes for an object type by selecting
the Clear All tool

10 Select or clear object and option checkboxes for each object type that
you want to reverse engineer.
11 Click OK.
The progress of the generation is shown in the Output window.
At the end of the generation, the new PDM appears in the PDM window.

165
Generating a PDM from a database creation script

Generating a PDM from a database creation


script
You can generate a PDM, or add PDM objects directly from a database
creation script.

v To generate a PDM from a script:


1 Select Database➤Reverse Engineering.
The Reverse Engineering a database dialog box appears.

2 Click the radio button labeled Using a Script File.


3 Select a script file name from the dropdown listbox.
or
Browse to a directory that contains a script file.
Select the script file and click OK.
The path of the script file appears in the listbox.
4 Click the Reverse button.
The progress of the generation is shown in the Output window.
At the end of the generation, the new PDM appears in the PDM window.

Multiple script files


If you have several script files, combine all the script files into a single
master file before performing reverse engineering.

166
C H A P T E R 6

Triggers and Procedures

About this chapter This chapter presents triggers and procedures used to generate database
constraints.
Contents
Topic Page

Trigger overview 168


Using triggers 170
Using trigger templates 183
Using template items 200
Defining stored procedures and functions 215
Using macros 218
Generating triggers and procedures 227

167
Trigger overview

Trigger overview
What is a trigger? A trigger is a segment of SQL code associated with a table, and stored in a
database. It is invoked automatically whenever there is an attempt to modify
data in the associated table with an insert, delete, or update command.
You can use triggers to enforce referential integrity, where declarative
constraints are not sufficient.

How are triggers used in PowerDesigner?


Creating triggers Triggers are defined for tables. In PowerDesigner there are two ways to
create a trigger for a table:

Trigger created… Description


Automatically The Rebuild Triggers function creates triggers for one or
more selected tables based on trigger templates defined in
the current model and current DBMS. Triggers are built
for tables that have Trigger referential integrity defined for
one or more references linking the table with a parent or
child table
Manually Trigger is defined manually for a specific table. You can
base the trigger on an existing trigger template, or type the
definition independently of a template

$ For more information on creating triggers automatically, see the section


Creating triggers automatically.
$ For more information on creating triggers manually, see the section
Creating a trigger manually.
Trigger templates A trigger template is a template for creating triggers. PowerDesigner ships
pre-defined templates for each supported DBMS. Depending on the current
DBMS, there are pre-defined templates for insert, update, and delete trigger
types. A trigger template can be stored in the model, or in the current DBMS.
Template items A template item is a reusable block of SQL script that can implement
referential integrity, or do any other work on database tables. A template item
is inserted into a trigger template script, or a trigger script. The template item
calls a corresponding SQL macro which can implement an insert, update,
delete, or error message constraint on one or more tables in the database.

168
Chapter 6 Triggers and Procedures

A template item can be stored in the current model, or in the current DBMS.
PowerDesigner ships pre-defined template items for each supported DBMS.
The type of pre-defined template items available depends on the current
DBMS.
The availability of The availability of a trigger template, or template item, to models other than
trigger templates the current model, depends on where the template is stored:
and template items
Template stored in Available to
Model Current model only
DBMS Link All models using the DBMS (.XDB file)
DBMS Local To Current model only
Model

Overview of trigger An overview of the creation of triggers by the Rebuild Triggers function is
creation by Rebuild shown below:
Triggers

169
Using triggers

Using triggers
A trigger is a segment of SQL code associated with a table, and stored in a
database. It is invoked automatically whenever there is an attempt to modify
data in the associated table with an insert, delete, or update command.
$ For an overview of how triggers are used in PowerDesigner, see the
section How are triggers used in PowerDesigner?

Trigger properties
Each trigger definition includes the following properties:

Property Description Length


Name Name of the trigger 254
Code Reference code of the trigger 254
template
Comment Descriptive label for the trigger 32Kb
Table Table attached to trigger —
Generate Indicates to generate trigger —
Definition Trigger definition code —
Preview Previews of trigger definition —
code
Template items Template items available for —
current DBMS

The Definition page of the trigger property sheet also includes the following
trigger properties:

Property Description
Template Template which trigger is based on
Type Type of trigger which is defined by the named template
Order Firing order of trigger

170
Chapter 6 Triggers and Procedures

Using variables in triggers

You can use variables in triggers, trigger templates, and template items. At
trigger generation these variables are replaced by values for a specific model
or table.
$ For a complete list of variables used in PowerDesigner, see the
appendix Variables in PowerDesigner.
Formatting You can also use formatting variables that have a syntax that can force a
variables format on their values, as follows:
♦ Force values to lower-case or upper-case characters
♦ Truncate the length of values
$ For a complete list of formatting variables used in PowerDesigner, see
the appendix Variables in PowerDesigner.

Creating triggers automatically


You can create triggers automatically for one or more tables in a model. The
triggers are created for references that have Trigger defined for referential
integrity implementation.
Rebuild triggers The Rebuild Triggers function automatically creates triggers for one or more
selected tables.
User-defined triggers defined for a table are always created independently of
trigger referential integrity constraints.
All other triggers created by Rebuild Triggers are built from trigger templates
defined in the DBMS and user-defined trigger templates defined in the
model. INSERT triggers are created for all selected tables. UPDATE and
DELETE triggers are created according to the trigger referential integrity
defined for the reference linking the table with a parent or child table.
Delete and rebuild You can create triggers by deleting existing triggers and rebuilding triggers
or preserve triggers based on referential integrity options, or you can choose to create triggers
and preserve all existing triggers.
Selecting triggers, The General page of the Rebuild Triggers dialog box shows the following
trigger templates, type of information organized hierarchically in a tree view:
and template items
♦ All trigger types supported by the current DBMS
♦ All trigger templates corresponding to the trigger types
♦ All template items defined for each trigger template
171
Using triggers

You can select trigger types, trigger templates, and template items by
expanding the appropriate nodes and selecting or clearing the checkboxes as
required.
The Rebuild Triggers General page for Sybase Adaptive Server Anywhere 6
is shown below. The node for the BeforeInsert Trigger is expanded showing
the BeforeInsertTrigger template that it is based on, and the two template
items InsertChildParentExist and InsertToo Many Children:

Template items When you select a template item it is included in the corresponding trigger
template. If a trigger is generated from the template, the template item is
generated in the trigger script if one of the following criteria apply:
♦ Template item implements trigger referential integrity constraints that
apply to a reference. A template item can therefore be defined in a
trigger template, but will only exist in the generated trigger if it
implements the referential integrity defined for a reference
♦ Template item is user defined. User-defined template items for a
generated trigger are generated independently of referential integrity
constraints

172
Chapter 6 Triggers and Procedures

Trigger as You must select Trigger as the implementation option for referential
referential integrity integrity, for one or more of the references attached to the table. This can be
option done on the Integrity page for the relevant reference.
You can select Trigger as the implementation option for multiple references,
by selecting Trigger from the Implementation dropdown listbox for each
reference from the List of References.
$ For more information on selecting referential integrity options from the
Reference property sheet, see the section Defining referential integrity in the
chapter Building Physical Data Models.

v To create a trigger automatically:


1 Select Tools➤Rebuild Triggers.
The Rebuild Triggers dialog box appears. The General page shows a tree
view containing the names of available triggers based on existing trigger
templates.

2 Select the Delete and Rebuild radio button if you want to delete all
existing triggers and rebuild using trigger templates.
or
Select the Preserve radio button if you want to keep all existing triggers
and create triggers using trigger templates.

173
Using triggers

Verify that Trigger is referential integrity selection


Triggers are only created automatically for tables that have Trigger
selected as the referential integrity implementation option in property
sheets for one or more references attached to each table.

3 Select checkboxes for triggers that you want to create.


or
Clear checkboxes for triggers that you do not want to create.
4 Expand a selected trigger node.
The trigger template node appears. This is the trigger template which is
used to create the trigger.
5 Expand the trigger template node.
The template item nodes appear. These are the template items that are
contained in the trigger template definition.
6 Select template item checkboxes for template items that you want to
include in the trigger definition.
or
Clear template item checkboxes for template items that you do not want
to include in the trigger definition.
7 Expand other trigger nodes and select or clear checkboxes for template
items as appropriate.
8 Click the Selection tab.
The Selection page appears. It lists all the tables in the model.
9 Select checkboxes for tables for which you want to create a trigger.
or
Clear checkboxes for tables for which you do not want to create a
trigger.
10 Click OK.
The rebuilding process is shown in the Output window. You can view
the triggers that have been created from the Triggers page of the table
property sheet, or from the List of Triggers. You can modify trigger
properties and its definition from the trigger property sheet.
$ For more information on modifying a trigger definition, see the
section Modifying a trigger.

174
Chapter 6 Triggers and Procedures

Creating a trigger manually


You can create a trigger manually from the table property sheet, using a
trigger template, or typing the trigger definition from scratch.
You must select Trigger as the implementation option for referential
integrity, for one or more of the references attached to the table. This can be
done on the Integrity page for the relevant reference.

v To create a trigger manually:


1 Double-click a table symbol.
The table property sheet appears.
2 Click the Triggers tab.
The Triggers page appears. It lists the triggers defined for the table.
3 Click a blank line in the list.
or
Click the Add a Row tool.
An arrow appears at the start of the line.
4 Type a trigger name and a trigger code.

Naming triggers
When you name a trigger, you cannot use a name that has already
been used for another trigger attached to the same table. Each new
trigger must have a name that is unique in the list.

5 Click Apply.
The creation of the new trigger is committed.
6 Click the new trigger line.
An arrow appears at the start of the line.
7 Click the Properties tool.
or
Double-click the arrow at the start of the line.
The property sheet for the new trigger opens to the General page.
8 Select the Generate checkbox.
or
Clear the Generate checkbox.
9 Click the Definition tab.

175
Using triggers

The Definition page appears.

10 Select a trigger template from the Template dropdown listbox.

Not using an existing trigger template


You can choose to not use a trigger template to create a trigger, by
selecting <None> from the Template dropdown list, and typing the
definition from scratch in the definition text box.

The type of trigger that is defined by the template appears in the Type
dropdown listbox, and the trigger definition appears in the text box.
11 Type modifications to the definition.
12 Select the order that you want the trigger to fire from the Order
dropdown listbox.

176
Chapter 6 Triggers and Procedures

Adding template items


You can also add template items to a trigger from the Definition page.
Template items are named reusable macros that can be inserted into
trigger scripts. They can be used for implementing referential
integrity constraints or doing any other work updating or modifying
tables in your database related to the trigger in which they are
inserted.

$ For more information on adding template items to a trigger, see the


section Modifying a trigger.
13 Click OK in each of the dialog boxes.

Modifying a trigger
You can customize a trigger as follows:
♦ Modifying its definition code directly. You can type changes to the
trigger definition, and also use editing tools to insert pre-defined
variables, operators, functions, and macros into the trigger definition
code.
♦ Inserting template items into the definition code to implement referential
integrity constraints, or do any work updating or modifying tables in the
database
.

Accessing a trigger You can modify a trigger from its property sheet. You can access a trigger
property sheet property sheet in several ways:
♦ From the table property sheet click the Triggers tab, select a trigger from
the list of triggers that appears, and click the Properties tool
♦ From the List of Triggers, select a trigger and click the Properties tool
♦ From the Browser, right-click the trigger node under the appropriate
table node in the tree view, and select Properties from the contextual
menu

Modifying other trigger properties


You can modify a trigger name, code, comment, the table that it is
attached to, and whether or not the trigger is generated, from the General
page of the trigger property sheet. When you name a trigger, you cannot
use a name that has already been used for another trigger attached to the
same table. Each new trigger must have a name that is unique in the list.

177
Using triggers

Inserting script You can modify a trigger definition by typing changes directly to the trigger
items script. You can insert pre-defined operators; variables, functions and macros
into the trigger definition by clicking on the appropriate tool from the Insert
Script tool bar, and selecting an item from the menu that appears. The
selected script item is inserted at the cursor position in the definition code.
You can use the following tools to insert script items into the trigger
definition:

Tool Inserts the following script item


Operator

Variable

Function

Macro

Adding template You can add a template item defined in the current model or defined in the
items current DBMS to a trigger definition. A template item can call a macro to
implement referential integrity, or perform any other type of action on
database tables.
$ For more information on creating and using template items, see the
section Using template items.

v To modify a trigger:
1 Click the Definition tab from the trigger property sheet.

178
Chapter 6 Triggers and Procedures

The Definition page appears. It shows the definition code of the trigger
template selected for the trigger.

2 Type modifications to the trigger code.


or
Click in the trigger definition where you want to insert a script item.
Click a script item tool.
Select a script item from the menu.
or
Click in the trigger definition where you want to insert a template item.
Click an Add Template Item tool.
Select a template item from the list that appears, and click OK.
3 Click OK in each of the dialog boxes.

179
Using triggers

Indicating trigger order


For a specified table, you can indicate the order that a trigger executes, or
fires, within a group of triggers of the same type.

v To indicate trigger order:


1 Click the Definition tab from the trigger property sheet.
The Definition page appears.
2 Select a number from the Order dropdown listbox.
This indicates the position in the firing order that the trigger fires.
3 Click OK in each of the dialog boxes.

Multiple triggers
Depending on the current DBMS, you can have multiple triggers of the same
type defined for any given table. Triggers of the same type are triggers that
are invoked for the same insert, update, or delete event.
Example A company is considering large numbers of candidates for new positions in
various posts. You want to ensure that all new employees will have a salary
that is within the range of others working in the same field, and less than his
or her prospective manager.
On an EMPLOYEE table, you create two BeforeInsert triggers,
tibTestSalry1_employee to verify that a proposed salary falls within the
correct range, and tibTestSalry2_employee to verify that the proposed salary
is less than that of the prospective manager.
create trigger tibTestSalry1 before insert order 1 on
EMPLOYEE
referencing new as new_ins for each row
begin
declare user_defined_exception exception for
SQLSTATE ’99999’;
declare salary_out_of_range_exception exception for
SQLSTATE ’99991’;
declare minsal integer;
declare maxsal integer;

/* Test if the salary of the new employee is between the


minimum salary */
/* and the maximum salary of other employees working in
this function */
select min(EMPSAL), max(EMPSAL)
into minsal, maxsal

180
Chapter 6 Triggers and Procedures

from EMPLOYEE
where EMPFUNC=new_ins.EMPFUNC;

if (minsal<>0 and maxsal<>0 and


(new_ins.EMPSAL>maxsal or new_ins.EMPSAL<minsal))
then
signal salary_out_of_range_exception
end if;
exception
when salary_out_of_range_exception then
message ’Error: Salary is out of range for the
function’;
signal user_defined_exception;
when others then
message ’Exception in before insert
trigger(%TRIGGER%) of table %OWNERPREFIX%%TABLE%’;
resignal;
end

create trigger tibTestSalry2 before insert order 2 on


EMPLOYEE
referencing new as new_ins for each row
begin
declare user_defined_exception exception for
SQLSTATE ’99999’;
declare higher_salary_than_manager_exception
exception for SQLSTATE ’99992’;
declare mansal integer;

/* Test if the salary of the new employee is superior to


the salary of*/
/* his or her future manager */
select EMPSAL
into mansal
from EMPLOYEE
where EMPNUM=new_ins.EMP_EMPNUM;

if mansal<>0 and new_ins.EMPSAL>mansal


then
signal higher_salary_than_manager_exception
end if;
exception
when higher_salary_than_manager_exception then
message ’Error: salary is higher than the manager’s
salary’;
signal user_defined_exception;
when others then
message ’Exception in before insert
trigger(%TRIGGER%) of table %OWNERPREFIX%%TABLE%’;
resignal;
end

181
Using triggers

Previewing a trigger
You preview a trigger in order to display the generated contents of a trigger
with instantiated variables. You can preview a trigger from the Preview page
of the trigger property sheet.

v To preview a trigger:
♦ Click the Preview tab from the trigger property sheet.
The Preview page appears. The trigger definition appears in the preview
text box.
♦ Click OK in each of the dialog boxes.

182
Chapter 6 Triggers and Procedures

Using trigger templates


You can create triggers based on trigger templates. You can create your own
trigger templates, or use the pre-defined trigger templates delivered with
PowerDesigner. Trigger templates exist for each type of trigger supported by
the DBMS.
Why use trigger Trigger templates can be used in two ways:
templates?
Template use Description
Automatic creation The Rebuild Triggers function uses all trigger templates
of triggers defined in the DBMS and current model to automatically
create triggers for selected tables. Triggers are created for
tables that have Trigger defined as the implementation for
referential integrity for one or more references attached to
the table
As a base for There are trigger templates for each trigger type (update,
creating a trigger delete, or insert). Using a template allows you to quickly
create an update, delete, or insert trigger for a table

DBMS trigger DBMS trigger templates are defined in the current DBMS.
templates
The availability of DBMS trigger templates to other models depends on where
the templates are stored:

Template stored in Available to…


DBMS Link All models using the DBMS (.XDB file)
DBMS Local To Model Current model only

You can create a trigger template in the DBMS. You can also use and modify
the pre-defined trigger templates delivered with PowerDesigner.

Modifying DBMS Link templates


By modifying a DBMS Link template, you modify the .XDB file which
contains the DBMS definition in the DBMS library. This definition is
shared by all models using the DBMS Link. You should only modify a
DBMS Link definition that is a copy of the DBMS shipped with
PowerDesigner.

183
Using trigger templates

PowerDesigner The pre-defined DBMS templates that ship with PowerDesigner indicate
pre-defined DBMS referential integrity constraints for one of the three trigger types: insert,
templates update, and delete. Depending on the current DBMS, there is a before and
after event template for each trigger type.
You can modify the trigger definition in the PowerDesigner pre-defined
trigger templates, but they cannot be deleted or renamed.
$ For more information on creating and copying a DBMS, see the chapter
DBMS Basics.
User-defined A user-defined trigger template is any trigger template that has been created
trigger templates in the model or in the current DBMS.
Model trigger A model trigger template is a trigger template defined in a model. It can not
templates be used by other models. Model trigger templates are always user-defined.

Identifying PowerDesigner pre-defined trigger template types


The types of pre-defined DBMS trigger templates that are shipped with
PowerDesigner depend on the current DBMS for the model.
The following templates types exist, but are not available for all DBMS:
Insert templates
Template type Generates trigger or procedure that executes ...
InsertTrigger With insert
BeforeInsertTrigger Before insert
AfterInsertTrigger After insert
InsertProc When called by InsertTrigger
BeforeInsertProc When called by BeforeInsertTrigger
AfterInsertProc When called by AfterInsertTrigger

184
Chapter 6 Triggers and Procedures

Update templates
Template type Generates trigger or procedure that executes ...
UpdateTrigger With update
BeforeUpdateTrigger Before update
AfterUpdateTrigger After update
UpdateProc When called by UpdateTrigger
BeforeUpdateProc When called by BeforeUpdateTrigger
AfterUpdateProc When called by AfterUpdateTrigger

Delete templates
Template type Generates trigger or procedure that executes ...
DeleteTrigger With delete
BeforeDeleteTrigger Before delete
AfterDeleteTrigger After delete
DeleteProc When called by DeleteTrigger
BeforeDeleteProc When called by BeforeDeleteTrigger
AfterDeleteProc When called by AfterDeleteTrigger

185
Using trigger templates

Trigger template properties


Each trigger template definition includes the following properties:

Property Description Maximum


Length
Name Name of the trigger template 254
Code Reference code of the trigger template. The 254
code is generated in trigger script
Comment Descriptive label for the trigger template 32Kb
DBMS Current DBMS —
Trigger Type Type of trigger that the template defines. For —
example BeforeInsertTrigger
Trigger Name Name of trigger associated with template —
Definition Trigger template code —
Template items Template items that are generated when the —
trigger is generated

Template items in The Template Item page that can be accessed from the trigger template
a trigger template property sheet, lists the template items that are defined in the trigger template
and that will be generated when a trigger is generated from the template.
A template item that is deleted from the Template Items page is not deleted
from the trigger template definition.
You can therefore limit the template items available for generation by
removing template items from the Template Item page, without having to
remove them from the trigger template definition.
Rebuild triggers When you use Rebuild Triggers to automatically create triggers for selected
tables, the template items that are listed on this page are those that are
available to be generated. Whether they are generated or not depends on the
following:
♦ Template items are generated in a trigger if they match the trigger
implemented referential integrity defined for a reference attached to the
table
♦ Template items are generated in a trigger if they are user-defined. User-
defined template items are generated independently from trigger
referential integrity constraints

186
Chapter 6 Triggers and Procedures

Adding template You can add any template item from the model or DBMS to the Trigger
items to trigger template definition by clicking an Add Template Items tool from the
template definition Definition page of the trigger template property sheet, and selecting a
template item. It is automatically added to the Template Items page.

Using variables in trigger templates

You can use variables in triggers, trigger templates, and template items. At
trigger generation these variables are replaced by values for a specific model
or table.
$ For a complete list of variables used in PowerDesigner, see the
appendix Variables in PowerDesigner.
Formatting You can also use formatting variables that have a syntax that can force a
variables format on their values, as follows:
♦ Force values to lower-case or upper-case characters
♦ Truncate the length of values
$ For a complete list of formatting variables used in PowerDesigner, see
the appendix Variables in PowerDesigner.

Creating a trigger template


You can create two types of trigger templates:

Trigger template Created in current Available to


DBMS DBMS All models if created in a
DBMS that is linked
Current model only if created in
DBMS local to the model
Model Model Current model

There are two ways to create a trigger template:


♦ Renaming and editing a copy of an existing trigger template
♦ Creating a new template definition from scratch

187
Using trigger templates

Associating a You can associate a trigger name with a trigger template. It is recommended
trigger name with a that you follow trigger naming conventions when naming triggers. For
template example, tib2_%TABLE%.This helps prevent duplicating a trigger for the
same table.
$ For information on trigger naming conventions, see the section Trigger
naming conventions

188
Chapter 6 Triggers and Procedures

Creating a DBMS trigger template using an existing template


You create a DBMS Trigger Template in the Trigger Templates page from
the property sheet for the current DBMS.

v To create a DBMS trigger template using an existing template:


1 Select Database➤Edit Current DBMS.
The DBMS property sheet appears.
2 Click the Trigger Templates tab.
The Trigger Templates page appears.

3 Click the Create From DBMS Trigger Template tool.

A selection box appears. It lists all the trigger templates available in the
current DBMS.

189
Using trigger templates

4 Select a checkbox for the type of trigger template that you want to use as
the basis for your new template.
5 Click OK.
6 You return to the Trigger Templates page. The duplicate DBMS
template is listed.
7 Type a new name and code for the new template.
8 Click Apply.
The creation of the new template is committed.
9 Click the new template line.
An arrow appears at the beginning of the line.
10 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.
The property sheet for the new trigger template appears.

190
Chapter 6 Triggers and Procedures

11 Click the Definition tab.


The Definition page appears. It shows the definition of the template.
12 Type modifications to the template definition.
13 Click OK in each of the dialog boxes.
A confirmation box appears asking if you want to save the changes to the
DBMS.
14 Click Yes.

191
Using trigger templates

Creating a new DBMS trigger template


You create a new DBMS trigger template from the Trigger Templates page
in the property sheet for the current DBMS.

v To create a new DBMS trigger template:


1 Select Database➤Edit Current DBMS.
The DBMS property sheet appears.
2 Click the Trigger Templates tab.
The Trigger Templates page appears.
3 Click a blank line in the list.
or
Click the Add a Row tool.
An arrow appears at the beginning of the line.
4 Type a Template name and code.
5 Click Apply.
The creation of the new template is committed.
6 Click the new template line.
An arrow appears at the beginning of the line.
7 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.
The property sheet for the new trigger template appears.
8 Click the Definition tab.
The Definition page appears.
9 Type the template definition.
10 Click OK in each of the dialog boxes.
A confirmation box appears asking if you want to save the changes to the
DBMS.
11 Click Yes.

192
Chapter 6 Triggers and Procedures

Creating a model trigger template using an existing template

v To create a model trigger template using an existing template:


1 Select Model➤Trigger Templates.
The List of User Defined Trigger Templates appears.
2 Click the Create From DBMS Trigger Template tool.

A selection box appears. It lists all the trigger templates available in the
current DBMS.

3 Select a checkbox for the type of trigger template that you want to use as
the basis for your new template.
4 Click OK.
5 You return to the Trigger Templates page. The duplicate DBMS
template is listed.
6 Type a new name and code for the new template.
7 Click Apply.
The creation of the new template is committed.
8 Click the new template line.
An arrow appears at the beginning of the line.
9 Click the Properties tool.
or

193
Using trigger templates

Double-click the arrow at the beginning of the line.


The property sheet for the new trigger template appears.

10 Click the Definition tab.


The Definition page appears. It shows the definition of the template.
11 Type modifications to the template definition.
12 Click OK in each of the dialog boxes.

Creating a new model trigger template

v To create a new model trigger template:


1 Select Model➤Trigger Templates.
The List of User Defined Trigger Templates appears.
2 Click a blank line in the list.
or
Click the Add a Row tool.
An arrow appears at the beginning of the line.
3 Type a Template name and code.
4 Click Apply.
The creation of the new template is committed.
194
Chapter 6 Triggers and Procedures

5 Click the new template line.


An arrow appears at the beginning of the line.
6 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.
The property sheet for the new trigger template appears.
7 Click the Definition tab.
The Definition page appears.
8 Type the template definition.
9 Click OK in each of the dialog boxes.

Modifying a trigger template


You can customize a trigger template as follows:
♦ Modifying its definition code directly. You can type changes to the
trigger template definition, and also use editing tools to insert pre-
defined variables, operators, functions, and macros into the trigger
template definition code.
♦ Inserting template items into the definition code to implement referential
integrity constraints, or do any work updating or modifying tables in the
database
.

No restore default value for trigger templates


By modifying the definition of a DBMS trigger template, you modify the
DBMS. If you modify a DBMS trigger template, you can not restore its
original value from the DBMS property sheet. You can use the Undo
function to return to previous modifications. It is recommended that you
only modify a copied version of a DBMS.

Inserting script You can modify a trigger template definition by typing changes directly to
items the template script. You can insert pre-defined operators; variables, functions
and macros into the trigger template definition by clicking on the appropriate
tool from the Insert Script tool bar, and selecting an item from the menu that
appears. The selected script item is inserted at the cursor position in the
definition code.
You can use the following tools to insert script items into the trigger template
definition:

195
Using trigger templates

Tool Inserts the following script item


Operator

Variable

Function

Macro

Adding template You can add a template item defined in the current model or defined in the
items current DBMS to a trigger template definition. A template item can call a
macro to implement referential integrity, or perform any other type of action
on database tables.
$ For more information on creating and using template items, see the
section Using template items.

Modifying a DBMS trigger template

v To modify a DBMS trigger template:


1 Select Database➤Edit Current DBMS.
The DBMS property sheet appears.
2 Click the Trigger Templates tab.
The Trigger Templates page appears.
The Trigger Templates page appears. It lists all the trigger templates
defined in the current DBMS.
3 Click a trigger template name in the list.
An arrow appears at the start of the line.
4 Click the Properties tool.
or
Double-click the arrow at the start of the line.
The Trigger Template property sheet appears.
5 Click the Definition tab.
The Definition page appears.
6 Type modifications to the trigger code.

196
Chapter 6 Triggers and Procedures

or
Click in the trigger template definition where you want to insert a script
item.
Click a script item tool.
Select a script item from the menu.
or
Click in the trigger template definition where you want to insert a
template item.
Click the Add Template Item tool.
Select a template item from the list that appears, and click OK.
7 Click OK.
A confirmation box appears asking if you want to save the changes to the
DBMS.
8 Click Yes.

Modifying a model trigger template

v To modify a model trigger template:


1 Select Model➤Trigger Templates.
The List of User Defined Trigger Templates appears.
2 Click a trigger template name in the list.
An arrow appears at the start of the line.
3 Click the Properties tool.
or
Double-click the arrow at the start of the line.
The Trigger Template property sheet appears.
4 Type modifications to the trigger template code.
or
Click in the trigger definition where you want to insert a script item.
Click a script item tool.
Select a script item from the menu.
or
Click in the trigger template definition where you want to insert a
template item.
Click the Add Template Item tool.
Select a template item from the list that appears, and click OK.
5 Click OK in each of the dialog boxes.

197
Using trigger templates

Trigger naming conventions


The pre-defined trigger templates that ship with PowerDesigner indicate
naming conventions for the trigger scripts that it generates. The naming
convention consists of a prefix indicating the trigger type followed by the
table code.
The default naming conventions include a variable (%L:TABLE). The name
of the resulting trigger script replaces this variable with a lower-case table
code. For example, a resulting trigger script may have the name ti_employee.

Changing trigger naming conventions


You can change the trigger naming convention in PowerDesigner pre-defined
DBMS trigger templates from the Trigger Templates page of the DBMS
property sheet.

v To change trigger naming conventions in a DBMS trigger template:


1 Select Database➤Edit Current DBMS.
The DBMS property sheet appears.
2 Click the Trigger Template tab.
The Trigger Templates page appears.
3 Click a trigger template line.
An arrow appears at the start of the line.
4 Click the Properties tool.
or
Double-click the arrow at the start of the line.
The Trigger Template property sheet appears.
5 Type a new trigger name in the Trigger Name text box at the bottom of
the page.
For example, mytempl_%TABLE%
6 Click OK in each of the dialog boxes.

198
Chapter 6 Triggers and Procedures

Calling a related procedure in a trigger template

Some target databases do not accept code within a trigger statement. For
these databases, a trigger template can call a related procedure as a
parameter, which is defined in a procedure template. In these cases,
procedure templates are listed in the list of trigger templates.
Example Informix does not accept code in trigger templates. The template
InsertTrigger calls the procedure in the form of the variable %PROC%, as
follows:
-- Insert trigger "[%QUALIFIER%]%TRIGGER%" for table
"[%QUALIFIER%]%TABLE%"
create trigger [%QUALIFIER%]%TRIGGER% insert on
[%QUALIFIER%]%TABLE%
referencing new as new_ins
for each row (execute procedure
%PROC%(.FKCOLN("new_ins.%COLUMN%", "", ",", "));")
/
The template InsertProc defines the procedure, as follows:
-- Insert procedure "%PROC%" for table
"[%QUALIFIER%]%TABLE%"
create procedure %PROC%(.FKCOLN("new_%.14L:COLUMN%
%COLTYPE%", "", ",", ")")
.DeclInsertChildParentExist
.DeclInsertTooManyChildren
define errno integer;
define errmsg char(255);
define numrows integer;

.InsertChildParentExist
.InsertTooManyChildren

end procedure;
/

199
Using template items

Using template items


Template items are named reusable blocks of script that can be inserted into
trigger templates or triggers.
In a generated trigger script, a template item calls a macro that implements a
trigger referential integrity constraint or does any other updating work on
tables in the database.
Example A trigger template for Sybase Adaptive Server Anywhere 6 contains the
following template item:
.InsertChildParentExist
This item corresponds to the following definition:
.FOREACH_PARENT()
/* Parent "[%PQUALIFIER%]%PARENT%" must exist when
inserting a child in "[%CQUALIFIER%]%CHILD%" */
if (.JOIN("new_ins.%FK% is not null", "", " and", ")
then")
begin
set found = 0;
select 1
into found
from dummy
where exists (select 1
from [%PQUALIFIER%]%PARENT%
where .JOIN("%PK% = new_ins.%FK%",
"and ", "", ");")
if found <> 1 then
message ’Error: Trigger(%TRIGGER%) of table
[%QUALIFIER%]%TABLE%’;
message ’ Parent code must exist when
inserting a child!’;
signal user_defined_exception;
end if;
end
end if;
.ENDFOR

200
Chapter 6 Triggers and Procedures

How are template Template items are inserted in a trigger or trigger template definition using a
items inserted in a point followed by the template item name: . template item name. For
trigger definition? example the script below contains two template items .InsertChildParentExist
and .InsertTooManyChildren:
/* Before insert trigger "%TRIGGER%" for table
"[%QUALIFIER%]%TABLE%" */
create trigger %TRIGGER% before insert order %ORDER% on
[%QUALIFIER%]%TABLE%
referencing new as new_ins for each row
begin
declare user_defined_exception exception for
SQLSTATE ’99999’;
declare found integer;
.InsertChildParentExist
.InsertTooManyChildren
end
/
Certain DBMS require that a cursor and variables are declared for each
template item before the template item name appears in the script. You can
use the following format to declare a template item:
.Decl template item name.
$ For more information on declaring template items in a trigger or trigger
template, see the section Declaring a template item in a trigger definition.
PowerDesigner PowerDesigner ships pre-defined template items for each pre-defined trigger
pre-defined template defined in the supported DBMS. The Rebuild Triggers function
template items uses both pre-defined and user-defined trigger templates to automatically
create triggers for selected tables.
In the pre-defined trigger templates, each pre-defined template item
corresponds to a referential integrity constraint. Although a pre-defined
template item is defined in a trigger template, it is only generated in a trigger
script if it implements the trigger referential integrity defined for a reference.
Template items have the following generation conditions:

Template item is listed in… Template item is…


Template Items page of trigger Available for generation
property sheet
Template Items page of trigger Generated
template property sheet

You can modify the definition of the PowerDesigner pre-defined template


items, but they cannot be deleted or renamed.

201
Using template items

User-defined You can create template items in the model or current DBMS.
template items
Unlike the PowerDesigner pre-defined template items, user-defined template
items are generated in triggers by Rebuild Triggers independently from
referential integrity constraints. If a user-defined template is listed on the
Template Items page of the trigger template property sheet, it will always be
generated in the trigger.
You can create a template item in the current DBMS. If the DBMS is a
DBMS Link, then the template item is available to other models using the
same DBMS. If the DBMS is local to the model, or if you create the template
item in the model, it is available only to the current model.

Modifying DBMS template items


By modifying a DBMS template item, you modify the template item
definition in the current DBMS. You should only modify a DBMS that is a
copy of the DBMS shipped with PowerDesigner.

$ For more information on creating and copying a DBMS, see the chapter
DBMS Basics.

Identifying template items


The PowerDesigner pre-defined template items that are available depend on
the current DBMS.
The following pre-defined template items exist, but are not available for all
DBMS.
Insert constraints The template items below implement referential integrity in insert trigger
templates.

Template item Integrity constraint Description


DeclInsertChildParentExist Mandatory parent Parent must exist when
InsertChildParentExist inserting a child
DeclInsertTooManyChildren Cannot exceed Cannot insert a child if
InsertTooManyChildren maximum cardinality maximum cardinality
constraint has been reached

202
Chapter 6 Triggers and Procedures

Update constraints The template items below implement referential integrity in update trigger
templates.

Template item Integrity constraint Description


DeclUpdateChildParentExist Mandatory parent Parent must exist
UpdateChildParentExist when updating a child
DeclUpdateChildChangeParent Change parent not Cannot modify parent
UpdateChildChangeParent allowed code in child
DeclUpdateParentRestrict Restrict on update Cannot modify parent
UpdateParentRestrict if child exists
DeclUpdateParentCascade Cascade on update Modify parent code in
UpdateParentCascade all children
DeclUpdateChangeColumn Non-modifiable Cannot modify
UpdateChangeColumn column column
DeclUpdateParentSetNull Set null on update Set parent code to null
UpdateParentSetNull in all children
DeclUpdateParentSetDefault Set default on update Set parent code to
UpdateParentSetDefault default in all children
DeclUpdateTooManyChildren Cannot exceed Cannot update a child
UpdateTooManyChildren maximum cardinality if maximum
constraint cardinality has been
reached

Delete constraints The template items below implement referential integrity in delete trigger
templates.

Template item Integrity constraint Description


DeclDeleteParentRestrict Restrict on delete Cannot delete parent if
DeleteParentRestrict child exists
DeclDeleteParentCascade Cascade on delete Delete parent code in all
DeleteParentCascade children
DeclDeleteParentSetNull Set null on delete Delete in parent sets
DeleteParentSetNull child to null
DeclDeleteParentSetDefault Set default on delete Delete in parent sets
DeleteParentSetDefault child to default

203
Using template items

Constraint You can insert the following template items in any trigger template. They
messages generate error messages that indicate the violation of an integrity constraint.

Template item Description


UseErrorMsgText Error handling without a message table
UseErrorMsgTable Error handling with a message table

Template item properties


Each template item definition includes the following properties:

Property Description Maximum length


Names Name of template item 254
Code Reference code of template item. The 254
code is generated in trigger scripts
Comment Descriptive label for the template item 32Kb
DBMS Current DBMS —
Definition Template item code —
Declaration Declaration for template item in trigger —
script

Using variables in template items

You can use variables in triggers, trigger templates, and template items. At
trigger generation these variables are replaced by values for a specific model
or table.
$ For a complete list of variables used in PowerDesigner, see the
appendix Variables in PowerDesigner.
Formatting You can also use formatting variables that have a syntax that can force a
variables format on their values, as follows:
♦ Force values to lower-case or upper-case characters
♦ Truncate the length of values
$ For a complete list of formatting variables used in PowerDesigner, see
the appendix Variables in PowerDesigner.

204
Chapter 6 Triggers and Procedures

Creating a template item


You usually create a template item when an existing template item is not
suitable, or to create a repeatable block of code to do updating work on tables
in the database.
You can create two types of template items:

Template item Created in current Available to


DBMS DBMS All models if created in a Link
DBMS
Current model only if created in
Local to Model DBMS
Model Model Current model

There are two ways to create a template item:


♦ Renaming and editing a copy of an existing DBMS template item
♦ Creating a new template item definition from scratch

Creating a DBMS template item using an existing template item

v To create a DBMS template item using an existing template item:


1 Select Database➤Edit Current DBMS.
The DBMS property sheet appears.
2 Click the Trigger Template Items tab.

205
Using template items

The Trigger Template Items page appears.

3 Click the Duplicate From DBMS Trigger Template item tool.

A selection box appears. It lists all the template items available in the
current DBMS.

4 Select a checkbox for the type of template item that you want to use as
the basis for your new template item.
5 Click OK.

206
Chapter 6 Triggers and Procedures

6 You return to the Trigger Template Items page. The duplicate DBMS
template item is listed.
7 Type a new name and code for the new template item.
8 Click Apply.
The creation of the new template item is committed.
9 Click the new template item line.
An arrow appears at the beginning of the line.
10 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.
The property sheet for the new template item appears.

11 Click the Definition tab.


The Definition page appears. It shows the definition of the template item.
12 Type modifications to the template item definition.
13 Click OK in each of the dialog boxes.
A confirmation box appears asking if you want to save the changes to the
DBMS.
14 Click Yes.

207
Using template items

Creating a new DBMS template item

v To create a new DBMS template item:


1 Select Database➤Edit Current DBMS.
The DBMS property sheet appears.
2 Click the Trigger Template Items tab.
The Trigger Template Items page appears.
3 Click a blank line in the list.
or
Click the Add a Row tool.
An arrow appears at the beginning of the line.
4 Type a template item name and code.
5 Click Apply.
The creation of the new template item is committed.
6 Click the new template item line.
An arrow appears at the beginning of the line.
7 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.
The property sheet for the new trigger template appears.
8 Click the Definition tab.
The Definition page appears.
9 Type the template item definition.
10 Click OK in each of the dialog boxes.
A confirmation box appears asking if you want to save the changes to the
DBMS.
11 Click Yes.

Creating a model template item using an existing template item

v To create a model template item using an existing template item:


1 Select Model➤Trigger Template Items.
The List of User Defined Trigger Template Items appears.

208
Chapter 6 Triggers and Procedures

2 Click the Create From DBMS Trigger Item tool.

A selection box appears. It lists all the trigger templates available in the
current DBMS.

3 Select a checkbox for the type of trigger template that you want to use as
the basis for your new template.
4 Click OK.
5 You return to the Trigger Templates page. The duplicate DBMS
template is listed.
6 Type a new name and code for the new template.
7 Click Apply.
The creation of the new template is committed.
8 Click the new template line.
An arrow appears at the beginning of the line.
9 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.

209
Using template items

The property sheet for the new trigger template appears.

10 Click the Definition tab.


The Definition page appears. It shows the definition of the template.
11 Type modifications to the template definition.
12 Click OK in each of the dialog boxes.

Creating a new model template item

v To create a new model template item:


1 Select Model➤Trigger Template Items.
The List of User Defined Trigger Template Items appears.
2 Click a blank line in the list.
or
Click the Add a Row tool.
An arrow appears at the beginning of the line.
3 Type a template item name and code.
4 Click Apply.
The creation of the new template item is committed.
5 Click the new template line.
210
Chapter 6 Triggers and Procedures

An arrow appears at the beginning of the line.


6 Click the Properties tool.
or
Double-click the arrow at the beginning of the line.
The property sheet for the new trigger template appears.
7 Click the Definition tab.
The Definition page appears.
8 Type the template item definition.
9 Click OK in each of the dialog boxes.

Modifying a template item

You can customize a template item by modifying its definition code directly.
You can type changes to the template item definition, and also use editing
tools to insert pre-defined variables, operators, functions, and macros into the
template item definition code.
.

No restore default value for trigger templates


By modifying the definition of a DBMS template item, you modify the
DBMS. If you modify a DBMS template item, you can not restore its
original value from the DBMS property sheet. You can use the Undo
function to return to previous modifications. It is recommended that you
only modify a copied version of a DBMS.

Inserting script You can modify a template item definition by typing changes directly to the
items template item script. You can insert pre-defined operators; variables,
functions and macros into the template item definition by clicking on the
appropriate tool from the Insert Script tool bar, and selecting an item from
the menu that appears. The selected script item is inserted at the cursor
position in the definition code.

211
Using template items

You can use the following tools to insert script items into the template item
definition:

Tool Inserts the following script item


Operator

Variable

Function

Macro

Modifying a DBMS template item

v To modify a DBMS template item:


1 Select Database➤Edit Current DBMS.
The DBMS property sheet appears.
2 Click the Template Items tab.
The Template Items page appears.
The Template Items page appears. It lists all the template items defined
in the current DBMS.
3 Click a template item name in the list.
An arrow appears at the start of the line.
4 Click the Properties tool.
or
Double-click the arrow at the start of the line.
The template item property sheet appears.
5 Click the Definition tab.
The Definition page appears.
6 Type modifications to the template item code.
or
Click in the trigger definition where you want to insert a script item.
Click a script item tool.
Select a script item from the menu.
7 Click OK.

212
Chapter 6 Triggers and Procedures

A confirmation box appears asking if you want to save the changes to the
DBMS.
8 Click Yes.

Modifying a model template item

v To modify a model template item:


1 Select Model➤Template Items.
The List of User Defined Template Items appears.
2 Click a template item name in the list.
An arrow appears at the start of the line.
3 Click the Properties tool.
or
Double-click the arrow at the start of the line.
The template item property sheet appears.
4 Type modifications to the template item code.
or
Click in the template item definition where you want to insert a script
item.
Click a script item tool.
Select a script item from the menu.
5 Click OK in each of the dialog boxes.

Declaring a template item in a trigger definition


Certain DBMS require that a cursor and variables are declared for each
template item before the template item name appears in the script. This can
be a statement that calls a corresponding procedure. You can use the
following format to declare a template item: Decl template item name.
For example, the trigger definition for Oracle 8 contains the
.DeclInsertChildParentExist statement which declares the following
.InsertChildParentExist template item:
-- Before insert trigger "[%QUALIFIER%]%TRIGGER%" for
table "[%QUALIFIER%]%TABLE%"
create trigger [%QUALIFIER%]%TRIGGER% before insert
on [%QUALIFIER%]%TABLE% for each row
declare
integrity_error exception;

213
Using template items

errno integer;
errmsg char(200);
dummy integer;
found boolean;
.DeclInsertChildParentExist
begin
.InsertChildParentExist
-- Errors handling
exception
when integrity_error then
raise_application_error(errno, errmsg);
end;
/
In a generated trigger script, .DeclInsertChildExist corresponds to the
following definition:
.FOREACH_PARENT()
-- Declaration of InsertChildParentExist constraint for
the parent "[%PQUALIFIER%]%PARENT%"
.DEFINE "CURSOR" "cpk%REFNO%_%.25L:TABLE%"
cursor %CURSOR%(.JOIN("var_%.L26:FK% %.L:COLTYPE%", "",
",", ") is")
select 1
from [%PQUALIFIER%]%PARENT%
where .JOIN("%PK% = var_%.L26:FK%", "and ")
and .JOIN("var_%.L26:FK% is not null", "and ",
"", ";")
.ENDFOR
You define a declaration statement for a template item in the Declaration
page from the template item property sheet. The declaration statement is
automatically inserted in the trigger script when the trigger is generated.
You can use editing tools to insert script items into the template item
declaration.
$ For a description of the editing tools available to insert script items in a
definition, see the section Modifying a template item.

214
Chapter 6 Triggers and Procedures

Defining stored procedures and functions


You can define stored procedures and functions for any DBMS that supports
them.
A user-defined function is a form of procedure that returns a value to the
calling environment for use in queries and other SQL statements.

Defining templates for stored procedures and functions


Templates for the creation of stored procedures and functions are defined in
the current DBMS. You can modify these templates.

Modifying the DBMS


When you modify the templates for stored procedures and functions, you
modify the current DBMS. It is recommended that you only edit or modify
a copy of a DBMS that is shipped with PowerDesigner.

v To define a template for stored procedures or functions:


1 Select Database➤Edit Current DBMS.
The DBMS property sheet opens to the General page.
2 Expand the Script node in the DBMS tree view.
Expand the Objects node.
3 Expand the Procedure node.
or
Expand the Function node.
4 Click CustomProc to edit the stored procedure template.
or
Click CustomFunc to edit the function template.
The Value textbox to the right of the tree view displays the template.
5 Type changes to the template.
6 Click OK.

215
Defining stored procedures and functions

Creating stored procedures and functions


You create stored procedures and functions using the structure of templates
defined in the current DBMS.
Inserting script When you create or modify the definition for a stored procedure or function,
items you can insert pre-defined operators; variables, functions and macros into the
trigger definition by clicking on the appropriate tool from the Insert Script
tool bar, and selecting an item from the menu that appears. The selected
script item is inserted at the cursor position in the definition code.
You can use the following tools to insert script items into the procedure or
function definition:

Tool Inserts the following script item


Operator

Variable

Function

Macro

v To create a stored procedure or a function:


1 Select Model➤Procedures.
The List of Procedures appears.
2 Click a blank line in the list.
or
Click the Add a Row tool.
An arrow appears at the beginning of the line.
3 Type a procedure or function name and code.
4 Click Apply.
The creation of the new procedure or function is committed.
5 Click the new procedure or function line.
An arrow appears at the start of the line.
6 Click the Properties tool.
or
Double-click the arrow at the start of the line.

216
Chapter 6 Triggers and Procedures

The property sheet for the new procedure or function opens to the
General page.
An arrow appears at the beginning of the line.
7 Click the Definition tab.
The Definition page appears.

8 Select Procedure from the dropdown listbox at the top of the page.
or
Select Function from the dropdown listbox at the top of the page.
The template definition appears in the text box.
9 Type the procedure or function definition code in the text box.

Inserting script items


You can insert script items into the definition as follows:
Click in the definition where you want to insert a script item. Click a
script item tool.
Select a script item from the menu.
The script item appears at the click point.

10 Click OK in each of the dialog boxes.

217
Using macros

Using macros
You can use predefined macros in trigger templates, template items, triggers,
and procedures. Macros perform specific functions.

AKCOLN
Description Repeats a statement for each alternate key in a table
Syntax .AKCOLN("statement","prefix","suffix","last_suffix", "condition")

Argument Description
statement Statement to repeat for each column
prefix Prefix for each new line
suffix Suffix for each new line
last suffix Suffix for the last line
condition Alternate key code (if condition argument is left empty the macro
returns a statement for each alternate key in the table)

Example In a trigger for the table TITLEAUTHOR, the following macro:


message .AKCOLN("’%COLUMN% is an alternate key
column’","", "", "", "AKEY1")
generates the following trigger script:
message ’TA_ORDER is an alternate key column’,

Column variable only


For columns, the macro AKCOLN only accepts the variable
%COLUMN%.

ALLCOL
Description Repeats a statement for each column in a table
Syntax .ALLCOL("statement","prefix","suffix","last_suffix")

Argument Description
statement Statement to repeat for each column

218
Chapter 6 Triggers and Procedures

Argument Description
prefix Prefix for each new line
suffix Suffix for each new line
last suffix Suffix for the last line

Example In a trigger for the table AUTHOR, the following macro:


.ALLCOL("%COLUMN% %COLTYPE%","",",",";")
generates the following trigger script:
AU_ID char(12),
AU_LNAME varchar(40),
AU_FNAME varchar(40),
AU_BIOGRAPH long varchar,
AU_ADVANCE numeric(8,2),
AU_ADDRESS varchar(80),
CITY varchar(20),
STATE char(2),
POSTALCODE char(5),
AU_PHONE char(12);

DEFINE
Description Defines a variable and initializes its value.
Syntax .DEFINE "variable" "value"

Argument Description
variable Variable name (without % signs)
value Variable value (may include another variable surrounded by %
signs)

Example In a trigger for the table AUTHOR, the following macro:


.DEFINE "TRIGGER" "T_%TABLE%"
message ’Error: Trigger(%TRIGGER%) of table %TABLE%’
generates the following trigger script:
message ’Error: Trigger(T_AUTHOR) of table AUTHOR’;

219
Using macros

DEFINEIF
Description Defines a variable and initializes its value if the test value is not null
Syntax .DEFINEIF "test_value" "variable" "value"

Argument Description
test_value Value to test
variable Variable name (without % signs)
value Variable value (may include another variable surrounded by %
signs)

Example For example, to define a variable for a default data type:


%DEFAULT%
.DEFINEIF "%DEFAULT%" "_DEFLT"" "%DEFAULT%"
Add %COLUMN% %DATATYPE% %_DEFLT%

ERROR
Description Handles errors
Syntax .ERROR (errno, "errmsg")

Argument Description
errno Error number
errmsg Error message

Example .ERROR(-20001, "Parent does not exist, cannot insert


child")

FKCOLN
Description Repeats a statement for each foreign key column in a table
Syntax .FKCOLN("statement","prefix","suffix","last_suffix")

Argument Description
statement Statement to repeat for each column
prefix Prefix for each new line
suffix Suffix for each new line

220
Chapter 6 Triggers and Procedures

Argument Description
last suffix Suffix for the last line

Example In a trigger for the table TITLEAUTHOR, the following macro:


message .FKCOLN("’%COLUMN% is a foreign key
column’","",",",";")
generates the following trigger script:
message ’AU_ID is a foreign key column,
TITLE_ISBN is a foreign key column;’

Column variable only


For columns, the macro FKCOLN only accepts the variable
%COLUMN%.

FOREACH_CHILD
Description Repeats a statement for each parent-to-child reference in the current table
fulfilling a condition
Syntax .FOREACH_CHILD ("condition")
"statement"
.ENDFOR

Argument Description
condition Reference condition (see below)
statement Statement to repeat

Condition Selects
UPDATE RESTRICT Restrict on update
UPDATE CASCADE Cascade on update
UPDATE SETNULL Set null on update
UPDATE SETDEFAULT Set default on update
DELETE RESTRICT Restrict on delete
DELETE CASCADE Cascade on delete
DELETE SETNULL Set null on delete
DELETE SETDEFAULT Set default on delete

221
Using macros

Example In a trigger for the table TITLE, the following macro:


.FOREACH_CHILD("DELETE RESTRICT")
-- Cannot delete parent "%PARENT%" if children still
exist in "%CHILD%"
.ENDFOR
generates the following trigger script:
-- Cannot delete parent "TITLE" if children still exist
in "ROYSCHED"
-- Cannot delete parent "TITLE" if children still exist
in "SALE"
-- Cannot delete parent "TITLE" if children still exist
in "TITLEAUTHOR"

FOREACH_COLUMN
Description Repeats a statement for each column in the current table fulfilling a condition
Syntax .FOREACH_COLUMN ("condition")
"statement"
.ENDFOR

Argument Description
condition Column condition (see below)
statement Statement to repeat

Condition Selects
empty All columns
PKCOLN Primary key columns
FKCOLN Foreign key columns
AKCOLN Alternate key columns
NMFCOL Non-modifiable columns (columns that have Cannot Modify
selected as a check parameter)
INCOLN Triggering columns (primary key columns, foreign key columns;
and non-modifiable columns)

Example In a trigger for the table TITLE, the following macro:


.FOREACH_COLUMN("NMFCOL")
-- "%COLUMN%" cannot be modified
.ENDFOR

222
Chapter 6 Triggers and Procedures

generates the following trigger script:


-- "TITLE_ISBN" cannot be modified
-- "PUB_ID" cannot be modified

FOREACH_PARENT
Description Repeats a statement for each child-to-parent reference in the current table
fulfilling a condition
Syntax .FOREACH_PARENT ("condition")
"statement"
.ENDFOR

Argument Description
condition Reference condition (see below)
statement Statement to repeat

Condition Selects references defined with ...


empty All references
FKNULL Non-mandatory foreign keys
FKNOTNULL Mandatory foreign keys
FKCANTCHG Non-modifiable foreign keys

Example In a trigger for the table SALE, the following macro:


.FOREACH_PARENT("FKCANTCHG")
-- Cannot modify parent code of "%PARENT%" in child
"%CHILD%"
.ENDFOR
generates the following trigger script:
-- Cannot modify parent code of "STORE" in child "SALE"
-- Cannot modify parent code of "TITLE" in child "SALE"

INCOLN
Description Repeats a statement for each primary key column, foreign key column,
alternate key column, or non-modifiable column in a table.
Syntax .INCOLN("statement","prefix","suffix","last_suffix")

223
Using macros

Argument Description
statement Statement to repeat for each column
prefix Prefix for each new line
suffix Suffix for each new line
last suffix Suffix for the last line

Example In a trigger for the table TITLE, the following macro:


.INCOLN("%COLUMN% %COLTYPE%","",",",";")
generates the following trigger script:
TITLE_ISBN char(12),
PUB_ID char(12);

JOIN
Description Repeats a statement for column couple in a join
Syntax .JOIN("statement","prefix","suffix","last_suffix")

Argument Description
statement Statement to repeat for each column
prefix Prefix for each new line
suffix Suffix for each new line
last suffix Suffix for the last line

Example In a trigger for the table TITLE, the following macro:


where .JOIN("%PK%=%FK%", " and", "", ";")
message ’Reference %REFR% links table %PARENT% to
%CHILD%’
generates the following trigger script:
message ’Reference TITLE_PUB links table PUBLISHER to
TITLE

Primary key, alternate key, and foreign keys variables only


For columns, the macro JOIN only accepts the variables %PK%, %AK%,
and %FK%.

224
Chapter 6 Triggers and Procedures

NMFCOL
Description Repeats a statement for each non-modifiable column in a table. Non-
modifiable columns have Cannot Modify selected as a check parameter.
Syntax .NMFCOL("statement","prefix","suffix","last_suffix")

Argument Description
statement Statement to repeat for each column
prefix Prefix for each new line
suffix Suffix for each new line
last suffix Suffix for the last line

Example In a trigger for the table TITLE, the following macro:


.NMFCOL("%COLUMN% %COLTYPE%","",",",";")
generates the following trigger script:
TITLE_ISBN char(12),
PUB_ID char(12);

PKCOLN
Description Repeats a statement for each primary key column in a table
Syntax .PKCOLN("statement","prefix","suffix","last_suffix")

Argument Description
statement Statement to repeat for each column
prefix Prefix for each new line
suffix Suffix for each new line
last suffix Suffix for the last line

Example In a trigger for the table TITLEAUTHOR, the following macro:


message .PKCOLN("’%COLUMN% is a primary key
column’","",",",";")
generates the following trigger script:
message ’AU_ID is a primary key column’,
’TITLE_ISBN is a primary key column’;

225
Using macros

Column variable only


For columns, the macro PKCOLN only accepts the variable
%COLUMN%.

226
Chapter 6 Triggers and Procedures

Generating triggers and procedures


You can create or modify database triggers and procedures directly using an
ODBC driver or indirectly using a script.
Generation parameters indicate the following:
♦ Triggers and procedures to generate
♦ Commands to generate in the trigger script
In both cases, the trigger generation commands are saved in a script file. You
must always provide the following information about the script file:

Parameter Description
DBMS Current DBMS
Directory Destination directory for the script file
File Name Destination filename for the script file
Generation Type Trigger generation by script or using ODBC
One File Only When selected creates one script file, instead of a separate
script file for each trigger

227
Generating triggers and procedures

Trigger and procedure creation parameters


The availability of generation parameters depends on the current DBMS.
Unavailable parameters display in gray and can not be selected.
The tables below indicate the generation that results from the selection of
generation parameters.
Trigger creation
parameters Parameter Resulting generation command
Create procedure Create procedure
Create trigger Create trigger
For insert Generate insert triggers
For update Generate update triggers
For delete Generate delete triggers

Procedure creation Parameter Resulting generation command


parameters
Create procedure Create procedure
Drop procedure Drop procedure

Generation script options

Script options indicate the format of generation scripts for triggers and
procedures.
Referential integrity options indicate whether to generate referential integrity
as a trigger or as a declarative statement.
The availability of these options depends on the current database.
Unavailable options display in gray and you cannot select them.

Option Result of selection


Windows (ANSI) Script uses ANSI character set
DOS (OEM) Script uses DOS character set
Uppercase Script contains all uppercase characters
Lowercase Script contains all lowercase characters

228
Chapter 6 Triggers and Procedures

Option Result of selection


No accent Non-accented characters replace accented characters in
script
Database prefix Table names in the script are prefixed by their database
names
Owner prefix Table names in the script are prefixed by their owner names
Title Each section of the script includes commentary in the form
of titles (for example, Database Name: TUTORIAL)
Check model Check the PDM before generating the database or script,
and stop generation if an error is found
Automatic archive Model is automatically archived after each generation

Error message
parameters Parameter Resulting generation command
Standard Generate standard error messages
User-defined Generate user-defined error messages

229
Generating triggers and procedures

Object selection parameters


You select tables for trigger generation, and procedures from the Selection
page.
Listing objects You can display in the list, tables or procedures in the current model, or in
contained in a individual packages contained in the model.
model or package
If you select the Include Sub-packages tool, you can display in the list either
all tables and procedures in the current model, or in a selected package.
You have the following selection options:

Include Sub-
Parent object packages Displays
Model Selected All tables or procedures in model including
all those contained in packages and sub-
packages
Model Not selected All tables or procedures in model except
those contained in packages and sub-
packages
Package Selected All tables or procedures contained in
package including all those contained in
sub-packages
Package Not selected All tables or procedures in package except
those contained in sub-packages

Listing objects for You can apply a filter to list only tables belonging to a particular owner. If
an owner you select the Owner <NONE> you display all the tables belonging to all
owners for the selected model or package.

Objects graphically selected in diagram


Objects graphically selected in a diagram can be automatically selected for
generation by clicking the Use Graphical Selection button in the Selection
page tool bar.

230
Chapter 6 Triggers and Procedures

Generating a trigger or procedure creation script


PowerDesigner generates trigger and procedure scripts that you can run in
your DBMS environment.

v To generate a trigger and procedure script:


1 Select Database➤Generate Triggers and Procedures.
The Triggers and Procedures Generation dialog box appears.

2 Type a directory name in the Directory box.


3 Type a filename in the File Name box.
4 Select the Script Generation radio button.
5 Select generation parameters.
6 Click the Options tab.
The Options page appears.
7 Select script options.
8 Click the Selection tab.

231
Generating triggers and procedures

The Selection page appears.


9 Select a model from the Model dropdown list.
10 If you want to generate a trigger script for tables owned by a particular
owner, select an owner from the Owner dropdown list.
or
If you want to generate a trigger script for tables owned by all owners in
the PDM, select None from the Owner dropdown list.
11 Click the Table or Procedure tab at the bottom of the page.
The Table or Procedure page appears listing the tables or procedures
available in the selected model or package.
12 Select checkboxes for tables containing triggers or procedures to
generate.
or
Clear checkboxes for tables containing triggers or procedures to
generate.
13 Click OK.
The Output window shows the progress of the generation process, and
indicates the syntax for running the script. At the end of script generation
a Result box appears. It lists the file path of the generated script file.
14 Click the Close button to close the Result box.
or
If you want to edit the script, click the file path in the result box and
click the Edit button.
The script opens up in a text editor.

232
Chapter 6 Triggers and Procedures

Creating triggers directly in a database


PowerDesigner can generate triggers directly. To do so, you must connect to
a data source via an ODBC driver.

v To create triggers directly in a database:


1 Select Database➤Generate Triggers and Procedures.
The Triggers and Procedures Generation dialog box appears.
2 Type a filename in the File Name box.
3 Type a directory name in the Directory box.
4 Select the ODBC Generation radio button.
5 Select generation parameters.
6 Click the Options tab.
The Options page appears.
7 Select script options.
8 Click the Selection tab.
The Selection page appears.
9 Select a model from the Model dropdown list.
10 If you want to generate a trigger script for tables owned by a particular
owner, select an owner from the Owner dropdown list.
or
If you want to generate a trigger script for tables owned by all owners in
the PDM, select None from the Owner dropdown list.
11 Click the Table or Procedure tab at the bottom of the page.
The Table or Procedure page appears listing the tables or procedures
available in the selected model or package.
12 Select checkboxes for tables containing triggers or procedures to
generate.
or
Clear checkboxes for tables containing triggers or procedures to
generate.
13 Click OK.
A dialog box asks you to identify a data source and connection
parameters.

233
Generating triggers and procedures

14 Select a machine data source from the dropdown listbox.


or
Select a file data source from the dropdown listbox.
15 Type your user ID and password.
16 Click Connect. If prompted by your data source, enter additional
connection parameters.
A message window shows the progress of the generation process.
17 Click OK.

Creating and generating user-defined error messages


You can create user-defined error messages. The error messages are stored in
a message table which you need to create in your database. When you select
trigger generation parameters, you can choose to generate an error message
from this table.
In the generated trigger script, the message table is called in a SELECT
command. If an error number in the script corresponds to an error number
value in the table column, then the standard error message is replaced by the
message defined in the table.

Creating a message table


You create a message table which stores error message information.

234
Chapter 6 Triggers and Procedures

v To create a message table:


1 Create a table with columns to store the following information:

Column to store… Description


Error number Number of the error message that is referenced in
the trigger script
Message text Text of message

2 Generate the table in your database.


3 Select Database➤Execute SQL.
A dialog box asks you to identify a data source and connection
parameters.
4 Select a data source and fill in connection parameters.
5 Click Connect.
An SQL query editor box appears.
6 Type an SQL statement to insert a message number and text in the
appropriate columns. You can use the following format:
insert into table values (error number,’error message’)
For example:
insert into ERR_MSG values (1004,’The value that you are
trying to insert does not exist in the referenced
table’)
7 Click Execute.
A message box tells you that the command has been successfully
executed.
8 Click OK.
You return to the SQL query box.
9 Click Close.

Generating a user-defined error message


You can choose to generate a user-defined error message from the trigger
generation parameters box.

v To generate a user-defined error message:


1 Select Tools➤Rebuild Triggers.
235
Generating triggers and procedures

The Rebuild Triggers dialog box appears.


2 Click the Error Messages tab.
The Error Messages page appears.
3 Select the User-defined radio button.
4 Type the name of the table that contains the error message in the
Message Table Name box.
5 Type the name of the column that contains the error number in the
Message Number box.
6 Type the name of the column that contains the error message text in the
Message Text column.
Below is an example of the details for a table called ERR_MSG.

7 Click the General tab and select the mode and triggers to create.
8 Click the Selection tab and select the tables for which you want to create
triggers.
$ For more information on rebuilding triggers see the section
Creating triggers automatically.
9 Click OK.
The trigger rebuilding process is shown in the Output window.
Select Database➤Generate Triggers and Procedures.
The Trigger and Procedure Generation dialog box appears.

236
Chapter 6 Triggers and Procedures

10 Select generation parameters as required.


11 Click OK.
$ For information on selecting trigger generation parameters, see the
section Generating triggers and procedures.

237
Generating triggers and procedures

238
C H A P T E R 7

Database Creation and Modification

About this chapter This chapter explains how to generate and modify databases using scripts and
via ODBC drivers.
Contents
Topic Page

Using the ODBC interface 240


Accessing a database 245
Configuring tablespace and storage 250
Customizing scripts 255
Generating a database 260
Modifying a database 272

239
Using the ODBC interface

Using the ODBC interface


The Open Database Connectivity (ODBC) interface allows PowerDesigner to
access data in different database management systems (DBMS) using
Structured Query Language (SQL) as a standard for accessing data.
An ODBC driver processes function calls and SQL requests coming from
PowerDesigner and sends them to a data source. It also returns request results
to PowerDesigner.
The data source provides all the target database information: its operating
system, DBMS, and network platform. You can define more than one data
source for the same driver.
There are two types of data sources:

Data source Description


Machine Named data source attributed to a user, or stored on a particular
system. Connection information is associated with the data
source name, so is limited to a specific user or system
File Data source stored as a file that is independent of any particular
user or system. Connection information can be shared among
several users, applications, and machines. A file data source can
also be defined as unsharable, limiting it to a single machine
which points to a machine data source

240
Chapter 7 Database Creation and Modification

Defining a data source


You define data sources using the program ODBC Administrator.
PowerDesigner gives you direct access to this program.

v To define a data source:


1 Select Database➤Connect.
A dialog box appears showing data source connection information.

2 Select the Machine data source radio button


or
Select the File Data Source radio button.
3 Click the Add button.
The ODBC Data Source Administration dialog box appears.
4 Click the Add button.
A list of available ODBC drivers appears.
5 Select a driver.
A list of available ODBC drivers appears.
6 Select a driver.
7 Click the Finish button.
A dialog box displays driver-dependent options.
8 Type or select information required by the DBMS.
9 Click OK in each dialog box.

241
Using the ODBC interface

Configuring a data source

You can use the ODBC administrator program to configure a data source.

v To configure a data source:


1 Select Database➤Connect.
A dialog box appears showing data source connection information.
2 Select Machine data source radio button.
Select a data source from the dropdown listbox.
or
Select the File data source radio button.
Browse to the directory that contains the .DSN file.
Select the .DSN file.
3 Click the Setup button.
A dialog box displays driver-dependent options. The ODBC
configuration dialog box for Adaptive Server Anywhere is shown below:

4 Type or select information required by the DBMS.


5 Click OK in each dialog box.

242
Chapter 7 Database Creation and Modification

Connecting to a data source


By connecting to a data source, you can send direct requests to a DBMS.

v To connect to a data source:


1 Select Database➤Connect.
A dialog box appears showing data source connection information.

2 Select the Machine Data Source radio button.


Select a data source from the dropdown listbox.
or
Select the File Data Source radio button.
Browse to the directory containing the .DSN file.
Select the .DSN file.
3 Type your user ID and password.
4 Click Connect and, if prompted by your data source, enter additional
connection parameters.

243
Using the ODBC interface

Displaying information about a connected database


The extent of information available about a database depends on the DBMS
and the ODBC driver in use.

v To display information about a connected database:


1 Connect to a data source.
2 Select Database➤Connection Information.

Disconnecting from a data source

v To disconnect from a data source:


♦ Select Database➤Disconnect.

244
Chapter 7 Database Creation and Modification

Accessing a database
PowerDesigner allows you to change the target database of your model,
display data from the database that corresponds to your model, and send SQL
queries to a connected data source.

Changing target DBMS


When you create a PDM, you select a target DBMS. If you change target
DBMS the PDM may be altered to become compatible with the new DBMS.
Preservation When you change DBMS, depending on which objects are supported by the
options old and new target DBMS, you can choose to preserve, or to lose, the values
associated with the following database objects:
♦ Triggers and stored procedures
♦ Physical options (on the database, tables, indexes, primary and alternate
keys, default options, tablespaces, and storages)
♦ Storages
♦ Tablespaces
♦ Abstract data types
If a database object is not supported by the old or new target DBMS, the
preserve option for that object is grayed and cannot be selected. If the new
target DBMS does not support an object, you will lose the values associated
with that object when you change target DBMS.
Syntax When you change target DBMS there can be syntax incompatibility between
incompatibility physical options.
If there is syntax incompatibility, you will lose the values for the physical
option that is not recognized by the new target database, even if you have
selected the checkbox to preserve that physical option.
Example If you are using physical option in while using Sybase Adaptive Server
Anywhere, and you change target database to Oracle 7 which does not
recognize the option in, you will lose all the values associated with that
option in your model.

245
Accessing a database

Link and Local to When you change the current DBMS, you can choose to connect to a target
the model DBMS DBMS in one of the following ways:

DBMS Description
Link Target DBMS for the PDM refers to the DBMS definition
file stored in the DBMS library. Any modifications made to
the DBMS are available to the linked PDM
Local to the model Target DBMS for the PDM is a copy of the DBMS
definition file stored in the DBMS library. The target
DBMS is independent of the original DBMS definition file
so any modifications made in the DBMS definition file in
the DBMS library are not available to the PDM. The
DBMS is saved with the PDM and can not be used
externally of it

v To change the target database for a PDM:


1 Select Database➤Change Current Database.
The Change DBMS Target dialog box appears.

2 Select a target DBMS from the dropdown listbox in the New groupbox.
3 Select the Link radio button.
or
Select the Local To The Model radio button.
4 Click the Options tab.

246
Chapter 7 Database Creation and Modification

The Options page appears. It displays options for database objects that
can be preserved or lost when the target DBMS is changed.

5 Select checkboxes for procedures and triggers, database objects, and


physical options that you want to preserve.

Preserve options selected by default


If you are changing target database within a database family, for
example between Sybase SQL Server 10 and Sybase SQL Server 11,
all preserve options available are selected by default. The checkboxes
for database objects not supported by the old and new target
databases are disabled.

6 Clear checkboxes for procedures and triggers, objects, and physical


options that you do not want to preserve.
7 Click OK.
8 A message box tells you the target database has been changed.
9 Click OK.
The name of the selected database appears in the status bar.

247
Accessing a database

Displaying data from a database


If the database corresponding to the PDM already exists, you can display the
data that corresponds to a table, view, or reference in the PDM.

v To display data from a connected database:


1 Right-click a table, view, or reference.
A context menu appears.
2 Select View Data from the context menu.
A dialog box asks you to identify a data source and connection
parameters.

3 Select the Machine Data Source radio button.


Select a data source from the dropdown listbox.
or
Select the File Data Source radio button.
Browse to the directory containing the .DSN file.
Select the .DSN file.
4 Type your user ID and password.
5 Click Connect and, if prompted by your data source, enter additional
connection parameters.
A Query Results windows list all the database records corresponding to
the selected table, view, or reference.
6 Click the Close button.

248
Chapter 7 Database Creation and Modification

Executing SQL queries


You can send SQL queries to a connected data source and display the results.

v To execute SQL queries:


1 Select Database➤Execute SQL.
A dialog box asks you to identify a data source and connection
parameters.
2 Select the Machine Data Source radio button.
Select a data source from the dropdown listbox.
or
Select the File Data Source radio button.
Browse to the directory containing the .DSN file.
Select the .DSN file.
3 Type your user ID and password.
4 Click Connect and, if prompted by your data source, enter additional
connection parameters.
A Queries window appears.

5 Type one or more SQL queries in the window.


The syntax of some SQL queries may be DBMS dependent.
6 Click the Execute button.
A list displays the results of your queries.
7 Click Close.
8 Click Cancel to close the Queries window.

249
Configuring tablespace and storage

Configuring tablespace and storage


Tablespace and storage indicate the physical location of tables and indexes in
a database or storage device. The definition of tablespace and storage is
DBMS specific. Different DBMS can use different terms for tablespace and
storage.
The terms tablespace and storage both refer to a named partition that stores
tables and indexes. Tablespace refers to a partition in a database. Storage
refers to a partition on a storage device.
For some DBMS, a tablespace can use a declared storage in its definition.

Sample tablespace and storage commands


The following table lists commands that implement PowerDesigner
tablespace and storage options in a selection of DBMS:

DBMS Tablespace Storage


Allbase CREATE DBEFILESET CREATE DBEFILE
DB2 CREATE TABLESPACE CREATE STOGROUP
Oracle 5 CREATE SPACE Not applicable
Oracle 6 or 7 CREATE TABLESPACE Storage structure
RDB 4 to 6 CREATE STORAGE MAP CREATE STORAGE AREA
SQLBase Not applicable CREATE STOGROUP
Sybase System 10 Not applicable SP-ADDSEGMENT
System 11
SQL Server
Sybase Adaptive CREATE DBSPACE Not applicable
Server
Anywhere
Watcom 3 or 4

Tablespace or storage not applicable


When tablespace or storage options are not applicable for a DBMS, the
corresponding Database menu item is grayed.

250
Chapter 7 Database Creation and Modification

Defining tablespace and storage


The lists of tablespace and storage options offer pre-defined parameters for
each DBMS where applicable. The lists show default values and value lists
for certain parameters which correspond to the recommended values for the
DBMS.
$ For information on tablespace and storage options for a particular
DBMS, see its reference manual.

v To define tablespace and storage:


1 Select Model➤Tablespaces.
or
Select Model➤Storages.
The List of Tablespaces or List of Storages appears.

Tablespace or storage not applicable


When tablespace or storage options are not applicable for a DBMS,
the corresponding Database menu item is grayed.

2 Click a blank line in the list.


or
Click the Add a Row tool.
An arrow appears at the beginning of the line.
3 Type a tablespace name and code.
or
Type a storage name and code.
4 Click the Properties tool.
The property sheet for the tablespace or storage appears.
5 Click the Options tab.

251
Configuring tablespace and storage

The Options page appears. The syntax page in the left pane lists the
database options available for a tablespace or storage. These options are
DBMS specific, and not all DBMS support options for tablespaces and
storages.

6 Select an option from the options listed on the Syntax page in the left
pane.
7 Click the Add button.
The name of the option appears on the Items page in the right pane
8 Select the option in the Items page in the right pane.

252
Chapter 7 Database Creation and Modification

The option name appears with an equals sign next to a text box at the
bottom of the dialog box. Depending on the type of value the option can
take, a dropdown listbox can appear instead of a text box.

9 Type a value for the option in the text box below the right pane
or
Select a value from the dropdown listbox below the right pane.
10 If you want to include more options in the tablespace or storage
definition, select other options and type or select their parameter values.
11 Click OK.

Previewing tablespace and storage commands


You can preview tablespace and storage commands before you generate
them.

v To preview tablespace and storage commands:


1 Select Model➤Tablespace.
or
Select Model➤Storage.
The list of tablespace or storage options appears.
2 Click a tablespace or storage item in the list.

253
Configuring tablespace and storage

An arrow appears at the beginning of the line.


3 Double-click the arrow at the start of the line.
or
Click the Properties tool.
The property sheet for the tablespace or storage appears.
4 Click the Preview tab.
The Preview page appears. It shows the corresponding command for the
target DBMS.

5 Click OK.

254
Chapter 7 Database Creation and Modification

Customizing scripts
You can customize scripts as follows:
♦ Insert scripts at the beginning and end of database creation script
♦ Insert scripts before and after a table creation command
Customizing a creation script allows you to add descriptive information about
a generated script, or manipulate the script in such a way that is not provided
by PowerDesigner.
Examples If a development project archives all the database creation scripts that are
generated, a header script can be inserted before each creation script, which
may indicate the date, time, and any other information specific to the
generated script.
If an organization requires that generated scripts are filed using a naming
system which may be independent from a script name, a header script could
direct a generated script to be filed under a different name than the name
indicated in the creation script.
Access rights can be added as a footer to a table creation script.

Inserting begin and end scripts for database creation


In a database creation script, you can insert the following scripts:

Script Where it is inserted


Begin script Before the command that creates the database
End script After the last command in the database creation script

255
Customizing scripts

You can use the following variables in these scripts:

Variable Description
%DATABASE% Name of the current PDM
%DATE% Date of script generation
%DBMSNAME% Name of the DBMS for the target database
%NAMESCRIPT% Filename of script file
%PATHSCRIPT% Filename and path of script file
%STARTCMD% Command that runs the script
%USER% Author of the current model

v To insert begin and end scripts for database creation:


1 Select Model➤Model Properties.
or
Right click the diagram background.
Select Properties from the context menu.
The model property sheet appears.

2 Click the Create tool next to the Database box.


A confirmation box appears asking you to commit the creation of the
database script object.

256
Chapter 7 Database Creation and Modification

3 Click Yes.
The database property sheet appears.

4 Type a name and code for the database.


5 Click the Script tab.
The Script page opens to the Begin page.
6 Type the DBMS-specific commands to insert in the beginning of the
script.
7 Click the End tab at the bottom of the page.
8 Type the DBMS-specific commands to insert at the end of the script.
9 Click OK in each of the dialog boxes.

257
Customizing scripts

Inserting begin and end scripts for table creation


For each table, you have the option to insert the following scripts:

Script Where it is inserted


Begin script Immediately before the table creation command (after the table
title)
End script Immediately after the table creation command

These scripts can appear in database creation scripts and database


modification scripts.
You can use the following variables in these scripts:

Variable Description
%COLNLIST% Column list
%DATABASE% Code of the current PDM
%DATE% Date of script generation
%DBMSNAME% Code of the DBMS for the target database
%NAMESCRIPT% Filename of script file
%OWNER% Table owner
%OWNERPREFIX% Owner prefix of table owner
%PATHSCRIPT% Filename and path of script file
%STARTCMD% Command that runs the script
%TABLE% Name or code of current table (based on display
preferences)
%TCODE% Code of the current table
%TLABL% Label of the current table
%TNAME% Name of the current table
%USER% Author of the current model

v To insert begin and end scripts for table creation:


1 Double-click a table symbol.
The table property sheet appears.
2 Click the Script tab.

258
Chapter 7 Database Creation and Modification

The Script page opens to the Begin page.


3 Type the DBMS-specific commands to insert in the beginning of the
script.
4 Click the End tab at the bottom of the page.
5 Type the DBMS-specific commands to insert at the end of the script.
6 Click OK.

Formatting variables in customized scripts


Variables have a syntax that can force a format on their values in the
following ways:
♦ Force values to lower-case or upper-case characters
♦ Truncate the length of values
When a variable does not specify formatting, its values have the same format
as in the PDM. You can use the following formatting syntax with variables:

Format code Format of variable value in script


.L Lower-case characters
.T Removes blank spaces
.U Upper-case characters
.n Maximum length where n is the number of characters
.nJ Justifies to fixed length where n is the number of characters

You embed formatting options in variable syntax as follows:


%.format:variable%
For example:
%.L:TABLE%

259
Generating a database

Generating a database
You can create or modify a database in two ways:
♦ Directly execute a script on a connected data source using an ODBC
driver
♦ Generate a script to be executed on a DBMS at a later time
In both cases, the database generation commands are saved in a script file.
You must always provide the following information about the script file:

Parameter Description
Directory Destination directory for the script file
File name Destination filename for the script file
One file only When selected creates one script file, instead of a separate script
file for each table
Generation Database generation by script or using ODBC
type

Creation parameters for tables, columns, and views


Creation parameters indicate what to generate from the database structure
defined by the PDM.
The availability of these parameters depends on the target database.
Unavailable parameters display in gray and you cannot select them.
Table creation
parameters Parameter Result of selection
Create table Generate tables
Check Generate check parameters and validation rules for tables
Physical options Generate physical options for tables
Begin script Insert customized script before table creation
End script Insert customized script after table creation
Comment Generate comment containing table label or name
Drop table Delete an existing table, before creating a new table

260
Chapter 7 Database Creation and Modification

Column creation
parameters Parameter Result of selection
User-defined type Generate user-defined data types
Default value Assign default value to column at creation
Check Generate check parameters and validation rules for column
Comment Generate comment indicating column label or name

View creation
parameters Parameter Result of selection
Create view Generate views
Comment Generate comment containing view label or name
Begin script Insert customized script before view creation
End script Insert customized script after view creation
Drop view Delete an existing view before creating a new view

Creation parameters for keys, indexes, and join indexes


Creation parameters indicate what to generate from the database structure
defined by the PDM.
The availability of these parameters depends on the target database.
Unavailable parameters display in gray and you cannot select them.
Primary key Parameter Result of the selection
creation
parameters Create primary key Generate primary keys
Physical options Generate physical options for primary keys
Drop primary key Delete an existing primary key, before creating a new
primary key

Alternate key Parameter Result of the selection


creation
parameters Create alternate key Generate alternate keys
Physical options Generate physical options for alternate keys
Drop primary key Delete an existing alternate key, before creating a new
alternate key

261
Generating a database

Foreign key Parameter Result of selection


creation
parameters Create foreign key Generate foreign keys
Decl. Integrity Generate declarative referential integrity for references that
have Declarative selected for referential integrity
implementation in the reference property sheet. When you
click the ellipsis button, a selection box appears which
allows you to define a filter to generate all or certain
references based on their defined referential integrity
constraints
Drop foreign key Delete an existing foreign key , before creating a new
foreign key

Index creation
parameters Parameter Result of selection
Create index Generate indexes
Physical options Generate physical options for indexes
Comment Generate comment containing index label or name
Drop index Deletes an existing index before creating a new index
Primary key Generate primary key indexes
Foreign key Generate foreign key indexes
Alternate key Generate alternate key indexes
Cluster Generate cluster indexes
Other indexes Generate indexes for all key columns with a defined index

Join index Parameter Result of selection


Create join index Generate join indexes
Begin script Insert customized script before join index creation
End script Insert customized script after join index creation
Drop join index Delete an existing join index, before creating a new join
index

262
Chapter 7 Database Creation and Modification

Database creation parameters


Creation parameters indicate what to generate from the database structure
defined by the PDM.
The availability of these parameters depends on the target database.
Unavailable parameters display in gray and you cannot select them.
Database
parameters Parameter Result of selection
Create database Generate database
Physical options Generate physical options for database
Begin script Insert customized script before database creation
End script Insert customized script after database creation
Open database Open database
Close database Close database
Drop database Delete an existing database, before creating new database

Tablespace and
storage Parameter Result of selection
parameters
Create tablespace Generate tablespaces
Drop tablespace Delete an existing tablespace, before creating a new
tablespace
Create storage Generate storages
Drop storage Delete an existing storage, before creating a new storage

User-defined data
type parameters Parameter Result of selection
Create data type Generate user-defined data types
Default value Default value for data type
Check Generate check parameters and validation rules for user-define
data types
Comment Generate comment containing data type label or name
Drop data type Delete an existing data type, before creating new data type

263
Generating a database

Abstract data type Parameter Result of selection


parameters
Create data type Define an abstract data type which is stored on a server
Drop data type Delete an existing abstract data type, before defining a
abstract data type
Install JAVA class Install a java class which is stored on a server
Remove JAVA class Delete an existing java class, before installing a new java
class

Generation script options


Script options indicate the format of database generation scripts.
The availability of these options depends on the target database. Unavailable
options display in gray and you cannot select them.
Script options
Option Result of selection
Windows Script uses ANSI character set
(ANSI)
DOS Script uses DOS character set
(OEM)
Upper Script contains all uppercase characters
Lower Script contains all lowercase characters
Mixed Script contains lowercase and uppercase characters
No accent Non-accented characters replace accented characters in script
Database Table and view names in the script are prefixed by their database
prefix names
Owner Table and view names in the script are prefixed by their owner
prefix names
Title Each section of the script includes commentary in the form of titles
(for example, Database Name: TUTORIAL)
Check Check the PDM before generating the database or script, and stop
model generation if an error is found
Automatic Model is automatically archived after each generation
archive

264
Chapter 7 Database Creation and Modification

Referential integrity
There are two ways to generate referential integrity in a database:

Option Result of selection


Trigger Generates a trigger
Declarative Generates a declarative statement in a script

You indicate referential integrity generation options from the Integrity page
of the reference property sheet.
You can define a filter to generate all or certain references based on their
defined referential integrity constraints, by clicking the ellipsis button next to
the Decl. Integrity option in the Database Generation dialog box, and
selecting or clearing the appropriate checkboxes.

Object selection parameters


You select objects for generation from the Selection page.
Listing objects You can display in the list, objects in the current model, or objects in
contained in a individual packages contained in the model.
model or package
If you select the Include Sub-packages tool, you can display in the list either
all objects in the current model, or all objects in a package.
You have the following selection options:

Include Sub-
Parent object packages Displays
Model Selected All objects in model including all objects
contained in packages and sub-packages
Model Not selected All objects in model except objects
contained in packages and sub-packages
Package Selected All objects contained in package including
all objects contained in sub-packages
Package Not selected All objects in package except objects
contained in sub-packages

Listing objects for You can apply a filter to list only objects belonging to a particular owner. If
an owner you select the Owner <NONE> you display all the objects belonging to all
owners for the selected model or package.

265
Generating a database

Graphically selected objects


Graphically selected objects in a diagram can be automatically selected for
generation by clicking the Use Graphical Selection button in the Selection
page tool bar.

Selecting objects for generation


When you generate a database you can select objects for generation from a
particular model. You can also apply a filter to limit the objects for
generation to those belonging to one or all owners in a PDM.
The Selection page is common to both the Database Generation and Database
Modification dialog boxes.

v To select objects for database generation:


1 From the Database Generation or Database Modification dialog box,
select the Selection tab.

266
Chapter 7 Database Creation and Modification

The Selection page appears. It displays objects for each object type in
the current model.

2 Select a model from the Model dropdown list.


3 If you want to generate a script for objects owned by a particular owner,
select an owner from the Owner dropdown list.
or
If you want to generate a script for all objects in the PDM, select None
from the Owner dropdown list.
4 Click an object type tab at the bottom of the page.
Select or clear checkboxes for objects to generate.
5 Select or clear object checkboxes for each object type that you want to
generate.

267
Generating a database

Generating a database creation script


PowerDesigner can generate a database creation script that you can run in
your DBMS environment.

v To generate a database creation script:


1 Select Database➤Generate Database.
The Database Generation dialog box appears. It lists generation
parameters for creating a database.

2 Type a destination directory for the script file in the Directory box.
3 Type a destination filename for the script file in the File Name box.
4 Select the Script radio button.
5 Select creation parameters for tables, columns, and views.
6 Click the Keys and Indexes tab.
The Keys and Indexes page appears. It lists creation parameters for
keys, foreign keys and indexes.
7 Select creation parameters for keys and indexes.

268
Chapter 7 Database Creation and Modification

8 Click the Database tab.


The Database page appears. It lists creation parameters for the database,
storages, tablespaces, and user-defined data types.
9 Select database creation options.
10 Click the Options tab.
The Options page appears. It lists formatting, checking, and archiving
options for the generated script.
11 Select script options.
12 Click the Selection tab.
The Selection page appears.
13 Indicate selection details and select or clear object checkboxes for each
type of PDM object to generate.
$ For more information on selecting a model, owners, and PDM
objects see the section Selecting objects for generation.
14 Click OK.
The Output window shows the progress of the generation process, and
indicates the syntax for running the script. At the end of script generation
a Result box appears. It lists the file path of the generated script file.
15 Click the Close button to close the Result box.
or
If you want to edit the script, click the file path in the result box and
click the Edit button.
The script opens up in a text editor.

Creating a database directly


PowerDesigner can generate database structure directly. To do so, you must
connect to a data source using an ODBC driver.

v To create a database directly:


1 Select Database➤Generate Database.
The Database Generation dialog box appears.
2 Type a destination filename for the script file in the File Name box.
3 Type a destination directory for the script file in the Directory box.
4 Select the ODBC Generation radio button.

269
Generating a database

5 Select creation parameters for tables, columns, and views.


6 Click the Keys and Indexes tab.
The Keys and Indexes page appears.
7 Select creation parameters for keys and indexes.
8 Click the Database tab.
The Database page appears.
9 Select database creation options.
10 Click the Options tab.
The Options page appears.
11 Select script options.
12 Click the Selection page.
The Selection page appears.
13 Indicate selection details and select or clear object checkboxes for each
type of PDM object to generate.
$ For more information on selecting a model, owners, and PDM
objects see the section Selecting objects for generation.
14 Click OK.
A dialog box asks you to identify a data source and connection
parameters.

15 Select a machine data source from the dropdown listbox.


or
Select a file data source from the dropdown listbox.
270
Chapter 7 Database Creation and Modification

16 Type your user ID and password.


17 Click Connect and, if prompted by your data source, enter additional
connection parameters.
A message window shows the progress of the generation process.
18 Click OK.

Archiving a PDM
When you generate a database from a PDM, you can save the PDM as an
archived file. You can use the archived PDM to synchronize the generation
of a database with a modified PDM.
You archive a PDM by selecting the Automatic Archive checkbox in the
Options page of the Database Generation dialog box.

271
Modifying a database

Modifying a database
You can generate a database by synchronizing a modified PDM with one of
the following existing database schema:
♦ Archived PDM
♦ ODBC data source
♦ Generation script file
The modified PDM and the existing database schema are merged using a
database synchronization window which displays an object tree view of the
modified PDM (source model) and the existing database schema (target
model). You can choose which objects are added, deleted, or updated in the
target database relative to the modified PDM.

Database generation synchronization parameters


You can select the following synchronization parameters:

Parameter Result of selection


Using an archive model Modified PDM is merged with an archived PDM
Using an ODBC data source Modified PDM is merged with a reverse
engineered database schema for an ODBC data
source
Using a script file Modified PDM script file is merged with an
existing database script file

Data preservation You can select the following database preservation parameters:
parameters
Parameter Result of selection
Create temporary tables Enforces creation of a temporary table to store data
from a modified table. A new table is then created, and
the data inserted into the new table from the temporary
table
Drop temporary tables If temporary table exists, drop temporary table after
generation of new table

272
Chapter 7 Database Creation and Modification

Database modification script options


Script options indicate the format of database generation scripts.
The availability of these options depends on the current database.
Unavailable options display in gray and you cannot select them.
Option Result of selection
Windows Script uses ANSI character set
(ANSI)
DOS Script uses DOS character set
(OEM)
Upper Script contains all uppercase characters
Lower Script contains all lowercase characters
Mixed Script contains lowercase and uppercase characters
No accent Non-accented characters replace accented characters in script
Database Table and view names in the script are prefixed by their database
prefix names
Owner Table and view names in the script are prefixed by their owner
prefix names
Title Each section of the script includes commentary in the form of titles
(for example, Database Name: TUTORIAL)
Check Check the PDM before generating the database or script, and stop
model generation if an error is found
Automatic Model is automatically archived after each generation
archive

Generating a modified database


You can generate a database creation script, or generate a database directly
by merging a modified PDM with one of the following existing database
schema:
♦ Archived PDM
♦ ODBC data source
♦ Generation script file

273
Modifying a database

Generating a database by synchronizing a PDM with an archived PDM

v To generate a database by synchronizing a PDM with an archived


PDM:
1 Select Database➤Modify Database.
The Database Modification dialog box appears. It lists generation
parameters for creating a database.

2 Type a destination directory for the script file in the Directory box.
Type a destination filename for the script file in the File Name box.
3 Select the Script radio button.
or
Select the ODBC Generation radio button.
4 Select the Using an Archive Model radio button.
5 Type the file path of the archived file
or
Click the button at the end of the box to browse to the directory
containing the archived PDM.
Select the archived PDM file, and click Open.
6 Select or clear checkboxes in the Data Preservation groupbox.

274
Chapter 7 Database Creation and Modification

7 Click the Options tab.


The Options page appears.
8 Select script options
9 Click the Selection tab.
The Selection page appears. It displays objects for each object type in
the current model.
10 Indicate selection details and select or clear object checkboxes for each
type of PDM object to generate.
$ For more information on selecting a model, owners, and PDM
objects see the section Selecting objects for generation.
11 Click OK.
The Database Synchronization window appears.
12 Select or clear checkboxes in the target model for objects that you want
to include or remove from the model.
$ For more information on comparing and merging models, see the
chapter Comparing and Merging Models in the PowerDesigner General
Features Guide.
13 Click OK.
♦ If you are generating a creation script, a at the generation end a
result box appears listing the file path of the generated script file. To
edit the script, click the file path in the result box and click the Edit
button. The script opens up in a text editor. To close the Result box,
click the Close button
♦ If you are generating a database directly, an ODBC Data Source
connection box appears. Enter connection details and click the
Connect button. A message window shows the progress of the
generation process. At the end of generation click OK to close the
box

275
Modifying a database

Generating a database by synchronizing a PDM with an ODBC data source

v To generate a database by synchronizing a PDM with an ODBC data


source:
1 Select Database➤Modify Database.
The Database Modification dialog box appears. It lists generation
parameters for creating a database.

2 Type a destination directory for the script file in the Directory box.
Type a destination filename for the script file in the File Name box.
3 Select the Script radio button.
or
Select the ODBC Generation radio button.
4 Select the Using an ODBC Data Source radio button.

276
Chapter 7 Database Creation and Modification

A dialog box asks you to identify a data source and connection


parameters.

5 Select a machine data source from the dropdown listbox.


or
Select a file data source from the dropdown listbox.
6 Type your user ID and password.
7 Click Connect and, if prompted by your data source, enter additional
connection parameters.
You return to the Database Modification dialog box.
8 Select or clear checkboxes in the Data Preservation groupbox.
9 Click the Options tab.
The Options page appears.
10 Select script options
11 Click the Selection tab.
The Selection page appears. It displays objects for each object type in
the current model.
12 Indicate selection details and select or clear object checkboxes for each
type of PDM object to generate.
$ For more information on selecting a model, owners, and PDM
objects see the section Selecting objects for generation.
13 Click OK.

277
Modifying a database

The ODBC Reverse Engineering dialog appears.

14 Indicate reverse engineering details and select or clear object


checkboxes for each type of PDM object to reverse engineer.
The database schema that you reverse engineer is the schema that is
synchronized with the current PDM to generate a modified database.
$ For more information on reverse engineering a database, and
selecting objects to reverse engineer, see the chapter Reverse
Engineering.
15 Click OK.
A progress box shows the progress of the reverse engineering process.
The Database Synchronization window appears.
16 Select or clear checkboxes in the target model for objects that you want
to include or remove from the model.
$ For more information on comparing and merging models, see the
chapter Comparing and Merging Models in the PowerDesigner General
Features Guide.
17 Click OK.
♦ If you are generating a creation script, a at the generation end a
result box appears listing the file path of the generated script file. To
edit the script, click the file path in the result box and click the Edit
button. The script opens up in a text editor. To close the Result box,
click the Close button

278
Chapter 7 Database Creation and Modification

♦ If you are generating a database directly, an ODBC Data Source


connection box appears. Enter connection details and click the
Connect button. A message window shows the progress of the
generation process. At the end of generation click OK to close the
box

Generating a database by synchronizing a PDM with a script file

v To generate a database by synchronizing a PDM with a script file:


1 Select Database➤Modify Database.
The Database Modification dialog box appears. It lists generation
parameters for creating a database.

2 Type a destination directory for the script file in the Directory box.
Type a destination filename for the script file in the File Name box.
3 Select the Script radio button.
or
Select the ODBC Generation radio button.
4 Type the file path of the script file
or

279
Modifying a database

Click the button at the end of the box to browse to the directory
containing the script file.
Select the script file, and click Open.
5 Select or clear checkboxes in the Data Preservation groupbox.
6 Click the Options tab.
The Options page appears.
7 Select script options
8 Click the Selection tab.
The Selection page appears. It displays objects for each object type in
the current model.
9 Indicate selection details and select or clear object checkboxes for each
type of PDM object to generate.
$ For more information on selecting a model, owners, and PDM
objects see the section Selecting objects for generation.
10 Click OK.
The Database Synchronization window appears.
11 Select or clear checkboxes in the target model for objects that you want
to include or remove from the model.
$ For more information on comparing and merging models, see the
chapter Comparing and Merging Models in the PowerDesigner General
Features Guide.
12 Click OK.
♦ If you are generating a creation script, a at the generation end a
result box appears listing the file path of the generated script file. To
edit the script, click the file path in the result box and click the Edit
button. The script opens up in a text editor. To close the Result box,
click the Close button
♦ If you are generating a database directly, an ODBC Data Source
connection box appears. Enter connection details and click the
Connect button. A message window shows the progress of the
generation process. At the end of generation click OK to close the
box

280
C H A P T E R 8

Generating a Conceptual Data Model from a


Physical Data Model

About this chapter This chapter describes how to generate a Conceptual Data Model from a
Physical Data Model.
Contents
Topic Page

Generating CDM objects 282


Translating PDM to CDM data types 283
Generating a CDM from a PDM 286
Generating and updating a PDM 295

281
Generating CDM objects

Generating CDM objects


When you generate a Conceptual Data Model (CDM) from a PDM,
PowerDesigner translates PDM objects and data types to CDM objects and
data types.

Translating PDM to CDM objects


CDM generation translates physical objects to conceptual objects as follows:

Object in a PDM Generated object in a CDM


Table Entity
Table column Entity attribute
Primary key Primary identifier
Alternate key Identifier
Reference Relationship

282
Chapter 8 Generating a Conceptual Data Model from a Physical Data Model

Translating PDM to CDM data types


PowerDesigner supports both physical and conceptual data types.

Translating physical data types


The following table lists the physical data types to which PowerDesigner
assigns translations:
Numeric data types Translation
example for SQL Code in Conceptual
Anywhere DBMS What it stores data type
integer I 32-bit integer Integer
smallint SI 16-bit integer Short Integer
integer LI 32-bit integer Long Integer
smallint BT 256 values Byte
numeric N Numbers with a fixed Number
decimal point
decimal DC Numbers with a fixed Decimal
decimal point
float F 32-bit floating decimal Float
numbers
real SF Less than 32-bit Short Float
floating decimal
number
double LF 64-bit floating decimal Long Float
numbers
numeric MN Numbers with a fixed Money
decimal point
numeric NO Automatically Serial
incremented numbers
numeric(1) BL Two opposing values Boolean
(true/false; yes/no; 1/0)

283
Translating PDM to CDM data types

Character data Translation


types example for SQL
Anywhere DBMS What it stores Conceptual data type
char A Character strings Characters
varchar VA Character strings Variable Characters
varchar LA Character strings Long Characters
long varchar LVA Character strings Long Var Characters
long varchar TXT Character strings Text
char MB Multibyte Multibyte
character strings
varchar VMB Multibyte Variable Multibyte
character strings

Time data types Translation


example for Conceptual data
SQL Anywhere DBMS What it stores type
Date D Day, month, year date
Time T Hour, minute, and time
second
Date & Time DT Date and time timestamp
Timestamp TS System date and time timestamp

284
Chapter 8 Generating a Conceptual Data Model from a Physical Data Model

Other data types Translation


example for SQL Conceptual data
Anywhere DBMS What it stores type
binary BIN Binary strings Binary
long binary LBIN Binary strings Long Binary
long binary PIC Images Image
long binary BMP Images in bitmap Bitmap
format (BMP)
long binary OLE OLE links OLE
char(10) * User-defined data Other
type
<undefined> <UNDE Not yet defined Undefined
F> data type

285
Generating a CDM from a PDM

Generating a CDM from a PDM


You can generate a CDM from a global PDM or from a package within the
model. Limiting CDM generation to a single package is useful when different
designers own packages of the same PDM. Designers can generate their
packages independently from others. Generating a package results in an
independent CDM.
You can generate a CDM in two ways:

Generate Description
New CDM Creates a new (default) CDM containing the objects translated
from the PDM
Updated CDM Create a default CDM that is then merged with an existing
CDM. You can choose to update, delete, or add objects in the
existing CDM (target model) based on modifications made in
the default CDM (source model).

$ For more information on merging two CDM, see the chapter Comparing
and Merging Models in the PowerDesigner General Features Guide.

Generating and updating a CDM


To generate a CDM, you must indicate to generate one of the following:
♦ Generate new Conceptual Data Model
♦ Update an existing Conceptual Data Model

Generate new You must indicate the following parameters when you generate a new CDM
Conceptual Data
Model Parameter Description
Name File name for the resulting PDM
Code Reference code for the resulting PDM

Update existing You must indicate the following parameters when you update an existing
Conceptual Data PDM:
Model

286
Chapter 8 Generating a Conceptual Data Model from a Physical Data Model

Parameter Description
Select Model Target Conceptual Data Model. This is the existing CDM that the
newly generated CDM (source model) is merged with to create
an updated CDM
Preserve When selected, allows a comparison and merge of the newly
Modifications generated CDM (default CDM) with the existing CDM

When Preserve Modifications is not selected


When Preserve modifications is not selected, PowerDesigner
automatically replaces the selected target model (existing CDM) with the
newly generated CDM. If you want to choose which objects to add or
delete from the target model, you must select Preserve Modifications to
compare and merge the two CDM.

CDM generation parameters and options


You can set the following general generation options:

Option Description
Check Model When selected verifies the model before generating the CDM,
and stops generation if an error is found
Save Generation When selected PowerDesigner keeps track of the identity of
Dependencies each generated object. This is useful when merging two CDM
which have been generated from the same PDM. Objects can
be compared and recognized as the same object, even if the
object has been modified in the target CDM
Model Notation Indicates the modeling methodology used in the generated
CDM. You can choose Entity/Relationship, Merise, or Mixed.
If you select Mixed, the two methodologies are available in the
same model

Check model before generation


If you select the Check Model option, the procedure to generate a CDM
starts by checking the validity of the PDM or package A CDM results
when no errors are found. You can set check options by selecting
Tools➤Check Model.

287
Generating a CDM from a PDM

Object selection parameters


You select objects for CDM generation from the Selection page.
Listing objects You can display in the list, objects in the current model, or objects in
contained in a individual packages contained in the model.
model or package
If you select the Include Sub-packages tool, you can display in the list either
all objects in the current model, or all objects in a package.
You have the following selection options:

Include Sub-
Parent object packages Displays
Model Selected All objects in model including all objects
contained in packages and sub-packages
Model Not selected All objects in model except objects
contained in packages and sub-packages
Package Selected All objects contained in package including
all objects contained in sub-packages
Package Not selected All objects in package except objects
contained in sub-packages

Graphically selected objects


Objects selected in your diagram can be automatically selected for
generation by clicking the Use Graphical Selection button in the Selection
page tool bar.

Generating a new CDM from a PDM


You can generate a CDM from a PDM or from a package in a PDM.
PowerDesigner creates a new CDM containing all the objects that you
selected to generate in the PDM. The newly created CDM appears in the
browser and the corresponding diagram opens in the work area.

288
Chapter 8 Generating a Conceptual Data Model from a Physical Data Model

You can only generate a CDM from the active PDM diagram.

v To generate a new CDM from a PDM:


1 Select Tools➤Generate Physical Model.
The CDM Generation Options dialog box appears.

2 Select the Generate New Conceptual Data Model radio button.


3 Type a new name and code for the new CDM.
You can choose to accept the default name and code for the new CDM.
In this case the new CDM has the same name and code as the PDM.
4 Click the Detail tab.

289
Generating a CDM from a PDM

The Detail page appears.

5 Select or type options and generation parameters.


6 Click the Selection tab.
The Selection page appears.

7 Select the name of a PDM from the Select Location dropdown list.

290
Chapter 8 Generating a Conceptual Data Model from a Physical Data Model

Generating a CDM from a package


To generate a CDM from a package, select the package name from
the Select Location dropdown listbox at the top of the page.
To generate CDM from a sub-package, select the Sub-Packages
Included icon next to the Selection Location dropdown listbox, and
then select a sub-package from the dropdown listbox.

8 Select table checkboxes for each entity that you want to generate.
or
Clear table checkboxes for each entity that you do not want to generate.
9 Click OK.
The Output window shows the progress of the generation process. The
new CDM diagram appears in the work area.

Updating an existing CDM


There are two ways to update an existing CDM depending on whether the
Preserve Modifications options is selected or not selected:

Preserve Modifications Result


Selected You can manually compare and merge existing
CDM (target model) with the newly generated
CDM( source model)
Not selected The existing CDM is automatically replaced by the
newly generated CDM

When you select the Preserve Modifications checkbox, the Merge Models
window appears after the new CDM has been successfully generated. You
can use the Merge window to select objects to be updated, deleted, or added
to the target model.
The target model must be open in the workspace to be merged with a source
model.
You can only generate a CDM from the active PDM diagram.

291
Generating a CDM from a PDM

v To update an existing CDM by generating from an PDM:


1 Select Tools➤Generate Conceptual Data Model.
The CDM Generation Options dialog box appears. If you do not have a
CDM in the current Workspace, the Update existing Conceptual Data
Model option is not available.

2 Select the Update Existing Conceptual Data Model radio button.


3 Select a target model from the Select Model dropdown listbox. This is
the existing model that you want to update.

Preserve modifications
If you want to preserve objects in the target CDM in order to compare
and merge the source and target models, you must select the Preserve
modifications checkbox. If you clear this checkbox, the existing CDM
is replaced with the newly generated CDM.

4 Click the Detail tab.

292
Chapter 8 Generating a Conceptual Data Model from a Physical Data Model

The Detail page appears.

5 Select or clear CDM generation options.


6 Click the Selection tab.
The Selection page appears.

7 Select the name of a PDM from the Select Location dropdown list. The
default CDM is generated from this PDM.

293
Generating a CDM from a PDM

Generating a CDM from a package


To generate a CDM from a package, select the package name from
the Select Location dropdown listbox at the top of the page.
To generate CDM from a sub-package, select the Sub-Packages
Included icon next to the Selection Location dropdown listbox, and
then select a sub-package from the dropdown listbox.

8 Select table checkboxes for each entity that you want to generate.
or
Clear table checkboxes for each entity that you do not want to generate
9 Click OK.
If you selected the Preserve Modifications checkbox, the Merge Models
window appears.
If you cleared the Preserve Modifications checkbox, the updated CDM
diagram appears in the work area.

Merging models
The Merge Models dialog box shows the newly generated CDM in
the Source Model pane, and the existing CDM in the Target Model
pane. You can select or clear object check boxes in the Source Model
pane for CDM objects that you want to be included or deleted in the
target model.

$ For more information on merging models, see the chapter


Comparing and Merging Models in the PowerDesigner General Features
Guide.

294
Chapter 8 Generating a Conceptual Data Model from a Physical Data Model

Generating and updating a PDM


You can generate a PDM in two ways:

Generate Description
New PDM Create a new PDM ( default PDM).
Updated PDM Create a default PDM that is then merged with an existing
PDM. You can choose to update, delete, or add objects in the
existing PDM (target model) based on modifications made in
the default PDM (source model).

$ For more information on merging two PDM, see the chapter Comparing
and Merging Models in the PowerDesigner General Features Guide.
To generate a PDM, you must indicate to generate one of the following:
♦ Generate new Physical Data Model
♦ Update existing Physical data Model

Generate new You must indicate the following parameters when you generate a new PDM:
Physical Data
Model Parameter Description
DBMS Database Management System definition (DBMS) for the
resulting PDM
Link DBMS for the resulting PDM refers to the DBMS definition
file stored in the DBMS library
Local to the Model DBMS for the resulting PDM is a copy of the DBMS
definition file stored in the DBMS library
Name File name for the resulting PDM
Code Reference code for the resulting PDM

295
Generating and updating a PDM

Update existing You must indicate the following parameters when you update an existing
Physical Data PDM:
Model
Parameter Description
Select Model Target Physical Data Model. This is the existing PDM
that the newly generated PDM (source model) is
merged with to create an updated PDM
DBMS Current Database Management System definition
(DBMS) for the existing PDM
Preserve Modifications When selected, allows a comparison and merge of the
newly created PDM (default PDM) with the existing
PDM

When Preserve Modifications is not selected


When Preserve modifications is not selected, PowerDesigner
automatically replaces the selected target model (existing PDM) with the
newly generated PDM. If you want to choose which objects to add or
delete from the target model, you must select Preserve Modifications to
compare and merge the two PDM.

PDM generation parameters and options


You have the following PDM generation options and parameters:

Option Description
Check Model When selected verifies the model before generating the PDM,
and stops generation if an error is found
Save Generation When selected PowerDesigner keeps track of the identity of
Dependencies each generated object. This is useful when merging two PDM
which have been generated from the same model. Objects can
be compared and recognized as the same object, even if the
object has been modified in the target PDM

Check model before generation


If you select the Check Model option, the procedure to generate a PDM
starts by checking the validity of the model or package A PDM results
when no errors are found. You can set check options by selecting
Tools➤Check Model.

296
Chapter 8 Generating a Conceptual Data Model from a Physical Data Model

Table parameters The following parameter defines the naming convention for tables:

Parameter Description
Table Prefix Prefix for the names of generated tables

Reference The following parameters define default referential integrity constraints:


parameters
Parameter Description
Update Rule Default update constraint for referential integrity
Delete Rule Default delete constraint for referential integrity

Index parameters The following parameters define naming conventions for indexes:

Parameter Description
PK index Naming convention for primary keys, by default %TABLE%_PK
names
Key index Naming convention for alternate keys, by default %TABLE%_AK
names
FK index Naming convention for foreign keys, by default %REFR%_FK
names
FK threshold Minimum number of estimated occurrences of an object necessary
to create an index on a foreign key

If you enter a value for the index threshold, indexes on foreign keys are only
generated if the number of estimated occurrences is greater than the
threshold. The estimated number of occurrences is a property that you can
include in the entity or class definition.
If an object has no specified number of occurrences, the foreign key indexes
are generated by default.

297
Generating and updating a PDM

PK and key index You can use the following variables in the PK index names and Key Index
name variables Names fields:

Variable Value
%TABLE% Generated code of the table. This is the table code that is
generated in the database. It may or may not be truncated if
the code contains characters not supported by the DBMS
%TNAME% Table name
%TCODE% Table code
%TLABL% Table comment

FK index name You can use the following variables in the FK index name field. The
variables generated code of a variable is the code defined in the object property sheet,
but which may or may not be truncated when generated if the code contains
characters not supported by the DBMS

Variable Value
%REFR% Generated code of the reference
%PARENT% Generated code of the parent table
%PNAME% Parent table name
%PCODE% Parent table code
%CHILD% Generated code of the reference
%CNAME% Child table name
%CCODE% Child table code
%PQUALIFIER% Parent table qualifier
%CQUALIFIER% Child table qualifier
%REFRNAME% Reference name
%REFRCODE% Reference code

298
C H A P T E R 9

Generating an Object-Oriented Model from


a Physical Data Model

About this chapter This chapter describes how you can generate an Object-Oriented Model
(OOM) from a Physical Data Model (PDM).
Contents
Topic Page

Generating OOM Objects 300


Translating PDM to OOM data types 301
Generating an OOM from a PDM 302

299
Generating OOM Objects

Generating OOM Objects


When you generate an object oriented model (OOM) from a PDM,
PowerDesigner translates PDM objects and data types to OOM objects and
data types supported by the current object language.

Translating PDM to OOM objects


OOM generation translates Physical Data Model objects into specified object
language objects as follows:

PDM Object Generated object in an OOM


Domain Domain
Table Class. The cardinality of a class is translated from the number of
estimated records in a table
Column Attribute
Key Identifier
Primary key Primary identifier
Stored- Operation
Procedure
Reference Association

300
Chapter 9 Generating an Object-Oriented Model from a Physical Data Model

Translating PDM to OOM data types


PowerDesigner supports both physical and object language data types.

Translating object language data types


The following table lists the physical data types to which the object language
definition assigns translations:

Translation
Physical Code in example with
data type PDM What it stores Java
Char A Character strings char
Numeric(1) BL Two opposing values boolean
(true/false; yes/no; 1/0)
Smallint BT 256 values byte
Integer SI 16-bit integer short
Integer LI 32 bit integer integer
Integer I 32 bit integer long
Float F 32 floating decimal numbers float
Numeric N Numbers with a fixed double
decimal point
Long varchar TXT Character strings String

301
Generating an OOM from a PDM

Generating an OOM from a PDM


You can generate a OOM from a global PDM or from a package within the
model. Limiting OOM generation to a single package is useful when different
designers own packages of the same PDM. Designers can generate their
packages independently from others. Generating a package results in an
independent OOM.
You can generate an OOM in two ways:

Generate Description
New OOM Creates a new (default) OOM containing the objects translated
from the PDM
Updated OOM Create a default OOM that is then merged with an existing
OOM. You can choose to update, delete, or add objects in the
existing OOM (target model) based on modifications made in
the default OOM (source model).

$ For more information on merging two OOM, see the chapter


Comparing and Merging Models in the PowerDesigner General Features
Guide.

Generating and updating an OOM


To generate a OOM, you must indicate to generate one of the following:
♦ Generate a new Object-Oriented Model
♦ Update an existing Object-Oriented Model

Generate new You must indicate the following parameters when you generate a new OOM:
Object-Oriented
Model Parameter Description
Object Language Target object language
Link Object language for the resulting OOM refers to the Object
language definition file stored in the Object language library
Local to the Model Object language for the resulting OOM is a copy of the
Object language definition file stored in the Object language
library
Name File name for the resulting OOM
Code Reference code for the resulting OOM

302
Chapter 9 Generating an Object-Oriented Model from a Physical Data Model

Update existing You must indicate the following parameters when you update an existing
Object-Oriented OOM:
Model
Parameter Description
Select Model Target Object-Oriented Model. This is the existing
OOM that the newly generated OOM (source model) is
merged with to create an updated OOM
Object Language Current object language definition for the OOM
Preserve Modifications When selected, allows a comparison and merge of the
newly generated OOM (default OOM) with the
existing OOM

When Preserve Modifications is not selected


When Preserve modifications is not selected, PowerDesigner
automatically replaces the selected target model (existing OOM) with the
newly generated OOM. If you want to choose which objects to add or
delete from the target model, you must select Preserve Modifications to
compare and merge the two OOM.

OOM generation options


You can set the following general generation options:

Option Description
Check Model When selected verifies the model before generating the OOM,
and stops generation if an error is found
Save Generation When selected PowerDesigner keeps track of the identity of
Dependencies each generated object. This is useful when merging two OOM
which have been generated from the same PDM. Objects can
be compared and recognized as the same object, even if the
object has been modified in the target OOM
Class Prefix Prefix for a class. It can help identify a class in a model

Check model before generation


If you select the Check Model option, the procedure to generate a OOM
starts by checking the validity of the PDM or package A OOM results
when no errors are found. You can set check options by selecting
Tools➤Check Model.

303
Generating an OOM from a PDM

Object selection parameters


You select objects for OOM generation from the Selection page.
Listing objects You can display in the list, objects in the current model, or objects in
contained in a individual packages contained in the model.
model or package
If you select the Include Sub-packages tool, you can display in the list either
all objects in the current model, or all objects in a package.
You have the following selection options:

Include Sub-
Parent object packages Displays
Model Selected All objects in model including all objects
contained in packages and sub-packages
Model Not selected All objects in model except objects
contained in packages and sub-packages
Package Selected All objects contained in package including
all objects contained in sub-packages
Package Not selected All objects in package except objects
contained in sub-packages

Graphically selected objects


Graphically selected objects in your diagram can be automatically selected
for generation by clicking the Use Graphical Selection button in the
Selection page tool bar.

Generating a new OOM from a PDM


You can generate a OOM from a PDM or from a package in a PDM.
PowerDesigner creates a new OOM containing all the objects that you
selected to generate in the OOM. The newly created OOM appears in the
browser and the corresponding diagram opens in the work area.

304
Chapter 9 Generating an Object-Oriented Model from a Physical Data Model

You can only generate a OOM from the active PDM diagram.

v To generate a new OOM from a PDM:


1 Select Tools➤Generate Physical Model.
The OOM Generation Options dialog box appears.

2 Select Generate a New Object-Oriented Model radio button.


3 Type a new name and code for the new OOM.
You can choose to accept the default name and code for the new OOM.
In this case the new OOM has the same name and code as the PDM.
4 Click the Detail tab.

305
Generating an OOM from a PDM

The Detail page appears.

5 Select or type options and generation parameters.


6 Click the Selection tab.
The Selection page appears.

7 Select the name of an OOM from the Select Location dropdown list.

306
Chapter 9 Generating an Object-Oriented Model from a Physical Data Model

Generating a OOM from a package


To generate a OOM from a package, select the package name from
the Select Location dropdown listbox at the top of the page.
To generate OOM from a sub-package, select the Sub-Packages
Included icon next to the Selection Location dropdown listbox, and
then select a sub-package from the dropdown listbox.

8 Select table checkboxes for each class that you want to generate.
or
Clear table checkboxes for each class that you do not want to generate.
9 Click OK.
The Output window shows the progress of the generation process. The
new OOM diagram appears in the work area.

Updating an existing OOM


There are two ways to update an existing OOM depending on whether the
Preserve Modifications options is selected or not selected:

Preserve Modifications Result


Selected You can manually compare and merge existing
OOM (target model) with the newly generated
OOM( source model)
Not selected The existing OOM is automatically replaced by the
newly generated OOM

When you select the Preserve Modifications checkbox, the Merge Models
window appears after the new OOM has been successfully generated. You
can use the Merge window to select objects to be updated, deleted, or added
to the target model.
The target model must be open in the workspace to be merged with a source
model.
You can only generate an OOM from the active PDM diagram.

v To update an existing OOM by generating from an PDM:


1 Select Tools➤Generate Object-oriented Model.

307
Generating an OOM from a PDM

The OOM Generation Options dialog box appears. If you do not have a
OOM in the current Workspace, the Update existing Object-Oriented
Model option is not available.

2 Select the Update Existing Object-Oriented Model radio button.


3 Select a target model from the Select Model dropdown listbox. This is
the existing model that you want to update.

Preserve modifications
If you want to preserve objects in the target OOM in order to compare
and merge the source and target models, you must select the Preserve
modifications checkbox. If you clear this checkbox, the existing
OOM is replaced with the newly generated OOM.

4 Click the Detail tab.

308
Chapter 9 Generating an Object-Oriented Model from a Physical Data Model

The Detail page appears.

5 Select or clear OOM generation options.


6 Click the Selection tab.
The Selection page appears.

7 Select the name of a PDM from the Select Location dropdown list. The
default OOM is generated from this PDM.

309
Generating an OOM from a PDM

Generating a OOM from a package


To generate a OOM from a package, select the package name from
the Select Location dropdown listbox at the top of the page.
To generate OOM from a sub-package, select the Sub-Packages
Included icon next to the Selection Location dropdown listbox, and
then select a sub-package from the dropdown listbox.

8 Select table checkboxes for each class that you want to generate.
or
Clear table checkboxes for each class that you do not want to generate
9 Click OK.
If you selected the Preserve Modifications checkbox, the Merge Models
window appears.
If you cleared the Preserve Modifications checkbox, the updated OOM
diagram appears in the work area.

Merging models
The Merge Models dialog box shows the newly generated OOM in
the Source Model pane, and the existing OOM in the Target Model
pane. You can select or clear object check boxes in the Source Model
pane for OOM objects that you want to be included or deleted in the
target model.

$ For more information on merging models, see the chapter


Comparing and Merging Models in the PowerDesigner General Features
Guide.

310
C H A P T E R 1 0

DBMS Definition Editor

About this chapter This chapter describes using the DBMS definition editor to edit a DBMS
definition. It also includes information on using variables in constraint name
templates and data type translations.
Contents
Topic Page

Using the DBMS Definition Editor 312

311
Using the DBMS Definition Editor

Using the DBMS Definition Editor


A DBMS in PowerDesigner is a DBMS definition file in .XML format that
contains specifications for a particular DBMS in a format understandable by
PowerDesigner. It provides PowerDesigner with the syntax and guidelines
for generating databases, triggers, and procedures appropriate for a target
DBMS.

Editing a DBMS definition


When you edit a DBMS in PowerDesigner, you actually edit the definition
of a DBMS. In the PowerDesigner interface and documentation, when
DBMS is used it refers to a DBMS definition file. An “actual DBMS” is
the DBMS motor for a database.

DBMS Overview
The DBMS is a required component of PowerDesigner when working with
Physical Data Models (PDM). It ensures that differences between actual
DBMS are handled correctly. Each actual DBMS supported by
PowerDesigner has its own DBMS definition file.
All DBMS have the same structure. Each DBMS is made up of a number of
categories. A category can contain sub-categories, fields, and field values.
These fields are parameters recognizable by PowerDesigner.
The values for DBMS fields vary for each current DBMS. Some fields may
not be available for a DBMS if that function does not apply to the specific
current DBMS.

The DBMS Editor


You can use the DBMS definition editor to consult or modify a DBMS. You
use the DBMS tree view to navigate through the DBMS categories and fields.
When you select a category or field, its comments and value (for a field) are
displayed in the zone to the right of the tree view.
The DBMS editor is contained on the General page of the DBMS property
sheet.
You can also edit trigger templates and trigger template items from the
Trigger Template and Template Item pages of the DBMS property sheet.

312
chapter 10 DBMS Definition Editor

DBMS categories
Each DBMS contains two principle categories:

Category Description
General Database and target database identification
Script Database characteristics, command definition, and data type
translations

Script category The Script category contains the following sub-categories:

Sub-category Description
SQL Contains sub-categories Syntax, Format, File, and Keywords.
Each sub-category contains field values which define database
characteristics
Objects Contains subcategories for each object in the database, for
example TABL (table), or REFR (reference).
Each sub-category contains field values which define database
commands and characteristics
Data Type Contains data type translation fields. These fields list the
correspondence between PowerDesigner internal data types
and the target DBMS data types

$ For a list of all the variables used in PowerDesigner, see the appendix
Variables in PowerDesigner.

Viewing DBMS fields


Each field in the DBMS definition editor has the following properties:

Field property Description


Name Name of category or field
Comment Description of selected category or field
Value Field value

313
Using the DBMS Definition Editor

DBMS field data PowerDesigner uses the following symbols to represent DBMS field data
types types:

Field symbol Data type


Single character

Single line text

Boolean

Numeric

Long text

v To view a DBMS:
1 Select Tools➤Resources➤DBMS.
A list of DBMS appears.

2 Select a DBMS.
3 Click the Properties tool.

314
chapter 10 DBMS Definition Editor

The DBMS property sheet appears. The General page contains a tree
view of all of the objects listed in the DBMS, and a DBMS definition
editor to the right of the tree view.

4 Expand the General or Script nodes as appropriate.


5 Select a field.
The name, associated comment, and value of the field appear in the zone
to the right of the explorer window.
6 Click the Close button.
You return to the current model.

315
Using the DBMS Definition Editor

Using the List of DBMS


You can perform the following DBMS management tasks from the List of
DBMS:

Tool Task Description


New Create a new DBMS by copying and renaming an
existing DBMS
Save Save the DBMS selected in the list

Save All Save all DBMS in the list

Import Import a DBMS into the DBMS library. You can


import a DEF file used with PowerDesigner version 6.
It is automatically saved as an .XDB file in XML
format.
Path Browse to the directory which contains a target DBMS

Properties Open the DBMS property sheet

$ For more information on creating a new DBMS, see the section


Creating a new DBMS.
$ For more information on importing a DBMS, or a PowerDesigner 6
DEF file, see the section Importing a DBMS or a PowerDesigner DEF file.

Creating a new DBMS


You can create a new DBMS by making a copy of an existing DBMS.
Creating a new DBMS is recommended when you want to modify a DBMS
definition. Modifying a copy of a DBMS allows you to keep the original
DBMS definition shipped with PowerDesigner intact.
You create a new DBMS from the List of DBMS.

316
chapter 10 DBMS Definition Editor

v To create a new DBMS:


1 Select Tools➤Resources➤DBMS.
A list of DBMS appears.

2 Click the New tool.


The New DBMS box appears.

3 Type a name for the new DBMS.


4 Select an existing DBMS from the Copy From dropdown listbox.
5 Click OK.
The new DBMS is added to the list of DBMS.
6

317
Using the DBMS Definition Editor

Importing a DBMS or a PowerDesigner DEF file


You can import a DBMS or a PowerDesigner DEF file into the DBMS
library. When you import a PowerDesigner DEF file it is imported as a .XDB
file.

v To import a DBMS or DEF file:


1 Select Tools➤Resources➤DBMS.
A list of DBMS appears.

2 Click the Import tool.


A standard file selection box appears.
3 Select or browse to the file that you want to import.
4 Click OK.
The file name appears in the list of DBMS.

Saving a DBMS
You save a DBMS from the List of DBMS.

v To save a DBMS:
♦ Select a DBMS in the List of DBMS.
♦ Click the Save tool.

318
chapter 10 DBMS Definition Editor

Saving all DBMS


You can save all DBMS in the DBMS library by clicking the Save All
tool from the List of DBMS.

Modifying a DBMS
Modifications that you make to a DBMS definition are applied differently
depending on whether the DBMS definition is a DBMS Link ,or Local to the
Model:

DBMS Description
Link Current DBMS for the PDM refers to the DBMS definition
file stored in the DBMS library. Any modifications made to
the DBMS are available to the linked PDM
Local to the model Current DBMS for the PDM is a copy of the DBMS
definition file stored in the DBMS library. The current
DBMS is independent of the original DBMS definition file
so any modifications made in the DBMS definition file in
the DBMS library are not available to the PDM. The
DBMS is saved with the PDM and can not be used
externally of it

When you modify a DBMS Link, you should always modify a copy of the
DBMS shipped with PowerDesigner.

319
Using the DBMS Definition Editor

DBMS edit menu When you right click a category or a field in the DBMS tree view, the
following editing options appear:

Edit option Description


Add items… Allows you to add a field which is missing in the list of fields in
a category.
When you select Add Items, the selected field is displayed in a
secondary tree view. When you double click this field, its
property sheet appears. You rename the field, and click OK on
each dialog box. The new field added at the bottom of the listed
fields for that category
Remove Deletes the selected category or field
Restore Restores the default comment for a selected category or field
Comment which has been modified
Restore value Restores the default value for a selected field which has been
modified

$ For a list of all the variables used in PowerDesigner, see the appendix
Variables in PowerDesigner.

v To modify a DBMS:
1 Select Tools➤Resources➤DBMS.
A list of DBMS appears.

2 Select a DBMS.

320
chapter 10 DBMS Definition Editor

Modifying a DBMS Link


If you are modifying a DBMS Link (you selected the Linked To radio
button when you choose the DBMS at PDM creation), you modify the
DBMS definition file in the DBMS library. This definition is shared
by all models using the DBMS Link. To ensure that you keep the
original DBMS definition, you should only modify a DBMS Link
definition that is a copy of the DBMS shipped with PowerDesigner.

3 Click the Properties tool.


The DBMS property sheet appears. The General page contains a tree
view of all of the objects listed in the DBMS, and a DBMS definition
editor to the right of the tree view.

4 Expand the nodes in the tree view window as appropriate.


5 Select a category or a field.
The name, comment, and value of the selected category or field appear
in the zone to the right of the tree view.
6 Modify the comment or value as required.

Right click edit menu


When you right click on a text zone in any dialog box, an edit menu
appears containing standard editing options.

7 Click the Close button.

321
Using the DBMS Definition Editor

The next time you open any PDM that uses the customized DBMS, the
PDM will take modifications into account. However, if you have
previously modified the same options directly in the PDM, the values in
the DBMS do not change these options.

Consulting trigger templates and template items


The DBMS contains the definition of trigger template and trigger template
items on the following pages:

DBMS page Contains definition for


Trigger Trigger templates
Templates
Template Items Trigger template items

You access the Trigger templates or Template items pages by clicking on the
corresponding tab.
Templates for stored procedures are defined under the Procedures node in the
DBMS tree view.
$ For information on using, creating, and editing trigger templates and
trigger template items, see the chapter Triggers and Procedures.

Defining constraint name templates


DBMS uses variable and variable formatting to define constraint name
templates. These are defined by the value of the DBMS field ConstName.
There are ConstName fields for the following object categories:

Category Description
TABLE Constraint name template for table checks
COLUMN Constraint name template for column checks
PKEY Constraint name template for primary keys
KEY Constraint name template for alternate keys
REFERENCE Constraint name template for foreign keys

322
chapter 10 DBMS Definition Editor

In PowerDesigner, you can define user-defined constraint names. Templates


apply to all constraints for which you do not define user-defined constraint
names.
Code and Many objects have Code and Generated Code variables which are
Generated code differentiated as follows:
variables
Variable Description
Code Attribute code defined in the property sheet
Generated Code Code computed according to generation options. The
generated code can be different from the code in the
following cases:
Code is a reserved word or contains invalid characters.
The generated code is quoted
Code is longer than the length authorized by the
DBMS. The generated code is truncated

$ For a list of all the variables used in PowerDesigner, see the appendix
Variables in PowerDesigner.
Common naming The ConstName field for all objects can accept the following common
variables for variables:
ConstName
Variable Description
%@OBJTNAME% Object name
%@OBJTCODE% Object code
%@OBJTLABL% Comment for the object
%@OBJTDESC% Description for the object

TABLE The ConstName field for the object TABLE can accept the following
ConstName variables:

Variable Value
%TABLE% Generated code of the table
%TNAME% Table name
%TCODE% Table code
%TLABL% Table comment

323
Using the DBMS Definition Editor

COLUMN The ConstName field for the object COLUMN can accept the following
ConstName variables:

Variable Value
%COLUMN% Generated column code
%COLNAME% Column name
%COLNCODE% Column code

PKEY ConstName The ConstName field for the object PKEY can accept the following variable:

Variable Value
%CONSTNAME% Constraint name

KEY ConstName The ConstName field for the object KEY can accept the following variables:

Variable Value
%AKEY% Code of the alternate key
%TABLE% Code of the table

324
chapter 10 DBMS Definition Editor

REFERENCE The ConstName field for the object REFERENCE can accept the following
ConstName variables:

Variable Value
%REFR% Generated code of the reference
%PARENT% Generated code of the parent table
%PNAME% Parent table name
%PCODE% Parent table code
%CHILD% Generated code of the reference
%CNAME% Child table name
%CCODE% Child table code
%PQUALIFIER% Parent table qualifier
%CQUALIFIER% Child table qualifier
%REFRNAME% Reference name
%REFRCODE% Reference code
%PKCONSTRAINT% Parent key constraint name used to reference the object
%POWNER% Parent table owner
%COWNER% Child table owner
%CHCKONCMMT% TRUE when check on commit is selected on the
reference (ASA 6.0 specific)

Example The following example shows the use of constraint name templates for
Sybase Adaptive Server Anywhere 6.
The DBMS Adaptive Server Anywhere 6 contains the following values for
the field ConstName:

Category Comment Value


PKEY Constraint name PK_%.U27:TABLE%
template for
Primary Keys
REFR Constraint name FK_%.U8:CHILD%_%.U9:REFR%_%.U8:
template for PARENT%
Foreign Keys
KEY Constraint name AK_%.U18:AKEY%_%.U8:TABLE%
template for
Alternate Keys

325
Using the DBMS Definition Editor

Category Comment Value


COLN Constraint name CKC_%.U17:COLUMN%_%.U8:TABLE%
template for Check
of Column
TABL Constraint name CKT_%.U26:TABLE%
template for Check
of Table

The resulting script that you could generate for a table using Adaptive Server
Anywhere 6 declares constraint names as follows:
create table DISCOUNT
(
DISCOUNT_ID T_IDENTIFIER not null,
STOR_ID T_AN_IDENTIFIER not null,
DISC_PERCENT T_PERCENT not null,
DISC_TYPE T_SHORT_TEXT null
constraint CKC_DISC_TYPE_DISCOUNT check
(DISC_TYPE in (’High’,’Medium’,’Low’)),
DISC_LOWQTY T_QUANTITY null ,
DISC_HIGHQTY T_QUANTITY null ,
constraint PK_DISCOUNT primary key (DISCOUNT_ID)
)
go

Formatting variables in a DBMS


Variables have a syntax that can force a format on their values, as follows:
♦ Force values to lowercase or uppercase characters
♦ Truncate the length of values
When a variable does not specify formatting, its values have the same format
as in the PDM.
$ For a list of all the variables used in PowerDesigner, see the appendix
Variables in PowerDesigner.
Example The following examples show format codes embedded in the variable syntax
for the constraint name template for primary keys, using a table called
CUSTOMER_PRIORITY:

Format
code Description Example Result
.L Lower-case PK_%.L:TABLE% PK_customer priority
characters

326
chapter 10 DBMS Definition Editor

Format
code Description Example Result
.T Removes blank PK_%.T:TABLE%
spaces
.U Upper-case PK_%.U:TABLE% PK_CUSTOMER
characters PRIORITY
.n Maximum length PK_%.8:TABLE% PK_Customer
where n is the
number of
characters
n Left justify variable PK_%8J:TABLE%
text to fixed length
where n is the
number of
characters
-n Right justify PK_%-8J:TABLE%
variable text to fixed
length where n is
the number of
characters

You embed formatting options in variable syntax as follows:


%.format:variable%
You can combine format codes. For example, %.U8:CHILD% formats the
code of the child table with a maximum of eight uppercase letters.

327
Using the DBMS Definition Editor

Defining data type translations


A CDM uses conceptual data types that are not DBMS-specific. A PDM uses
physical data types that are DBMS-specific.
The DBMS defines translations between conceptual data types to physical
data types.
The DBMS lists data type translations under the sub-category Data Type in
the following fields:

Field Data type translation


AmcdDataType Conceptual to physical
PhysDataType Physical to conceptual

You can transfer length and precision between conceptual data types and
physical data types.
The following symbols indicate length and precision:

Symbol Description
%n Length
%s Length for values that take a decimal point
%p Decimal precision

$ For more information on standard data types and their translation, see
the chapter Generating a Physical Data Model from a Conceptual Data
Model.
$ For a list of all the variables used in PowerDesigner, see the appendix
Variables in PowerDesigner.

328
chapter 10 DBMS Definition Editor

Defining reserved keywords


For a domain or a column, standard check fields can indicate minimum,
maximum, and default values, as well as a lists of values.
In general, if the data type of domain or column is a string data type,
quotation marks surround these values in the generated script. However,
quotation marks are not generated in the following cases:
♦ You define a data type that is not recognized as a string data type by
PowerDesigner
♦ Value is surrounded by tilde characters
♦ Value is a reserved keyword defined in the DBMS (for example, NULL)
In addition, if the value is already surrounded by quotation marks additional
quotation marks are not generated.
The generation of single- or double-quotation marks depends on the current
DBMS.
The DBMS lists reserved keywords as values for the field ReservedDefault,
under the category Keywords.
Example The following example shows the result of a reserved keyword for the DBMS
Sybase AS Anywhere 6.
Sybase AS Anywhere 6 DBMS contains the following lines:
ReservedDefault =
NULL
AUTOINCREMENT
CURRENT DATE
CURRENT PUBLISHER
CURRENT TIME
CURRENT TIMESTAMP
CURRENT USER
LAST USER

329
Using the DBMS Definition Editor

You define CURRENT DATE as the default value of a column:

The resulting script contains the string CURRENT DATE without quotation
marks.
create table SALE
(
SALE_ID T_IDENTIFIER not null,
STOR_ID T_AN_IDENTIFIER not null,
TITLE_ISBN char(12) not null,
SALE_DATE T_DATE not null
default CURRENT DATE,
SALE_AMOUNT T_AMOUNT ,
SALE_TERMS T_LONG_TEXT ,
SALE_QTY T_QUANTITY ,
primary key (SALE_ID)
);
When you run this script, Sybase Adaptive Server Anywhere will recognize
CURRENT DATE as a reserved default value.

330
chapter 10 DBMS Definition Editor

Defining default physical options in a DBMS


In a DBMS, you can set a value for the field DefOptions, which sets a
default value for physical options for the following object categories:

Category Default value for


DATABASE Database options
TABLE Table options
INDEX Index options
PKEY Primary key options
KEY Alternate key options
TABLESPACE Tablespace options
STORAGE Storage options

When an object is created in a PDM, it is assigned the default options defined


in the current DBMS.
You can generate the values from the PDM to a database. For example, you
can type a value for a storage option in the DBMS for Sybase System 11 as
follows:
DefTableOption = on my_segment
A database script you generate with this default value will include the line:
on my_segment
Instead of changing default physical option values in the DBMS using the
DBMS definition editor, you can change these values directly in the PDM.
$ For information on modifying default physical option values, see the
chapter Building Physical Data Models.

331
Using the DBMS Definition Editor

Defining physical options in a DBMS


A physical option is a parameter that defines how an object is optimized or
stored in a database. Physical options can be included at the end of a Create
statement and are DBMS specific. Examples of physical options are pctfree,
pctused, fillfactor, and partition.
Physical options for an object are defined in the Options field for the object
in the current DBMS. These physical options are then available in the
Options tab of the object property sheet.
Physical option Depending on the current DBMS, physical options are available in the
availability property sheets for the following objects:
♦ Tablespace
♦ Storage
♦ Database
♦ Table
♦ Index
♦ Key

Composite physical You can combine several physical options in a Create statement by using the
options syntax for a composite physical option. A composite physical option is a
physical option whose definition includes other physical options.
$ For more information on composite physical options, see the section
Composite physical option syntax.
$ For more detailed information on defining physical options and on
using the DBMS in general, see the DBMS Reference Guide. This document
is available for download from the Sybase website. You can contact
PowerDesigner customer support for the URL address.

Composite physical option syntax


A composite physical option is a physical option that includes other options.
The standard syntax for composite physical options is as follows:
<clustered> %s : list=clustered | nonclustered
with : composite=yes, separator=yes, parenthesis=no
{
fillfactor=%d : default=0
max_rows_per_page=%d : default=0

332
chapter 10 DBMS Definition Editor

}
on %s : category=storage

WITH physical The With physical option includes the other options, separated by a comma.
option
You can use the following keywords to define a composite physical option:

Keyword Value and result


Composite= If composite=yes, brackets can be used to define a complex physical
option
Separator= If separator=yes, the options are separated by a comma
If separator=no, the options have no separator character. This is the
default value
Parenthesis= If parenthesis=yes, the composite option is delimited by parentheses,
including all the other options, for example:
with (max_row_per_page=0, ignore_dup_key)
If parenthesis=no, nothing delimits the complex option. This is the
default value
Nextmand= If nextmand=yes, the next item is obligitory
Prevmand= If prevmand=yes, then the previous item is obligitory
Childmand= If childmand=yes, a child item is obligitory
Category= If category=tablspace, then item is linked to a tablespace
If category=storage, then item is linked to a storage
list= List in which values are separated by a pipe (|)
Dquoted= Value must be enclosed in double quotes ("" "")
Squoted= Value must be enclosed in single quotes (’ ’)

Example The above syntax is defined as follows in the Oracle 7 DBMS definition file:
initrans %d : default=1
maxtrans %d
tablespace %s : category = tablespace
storage : category=storage, composite=yes, separator=no,
parenthesis=yes
{
initial %s : default=10K
next %s : default=10K
minextents %d : default=1
maxextents %s
maxextents unlimited
pctincrease %d : default=50
freelists %d : default=1
freelist groups %d : default=1
optimal %d
optimal NULL
}
pctfree %d : default=10

333
Using the DBMS Definition Editor

nosort
<recoverable> %s : list=recoverable | unrecoverable
noparallel
parallel : composite=yes, separator=no, parenthesis=yes
{
degree %s : default=DEFAULT
instances %s : default=DEFAULT
}

Combining The keywords Default= and/or List= can also be used with the composite=,
keywords separator= and parenthesis= keywords.
The keyword Category= can be used with the three keywords of a complex
option.
For example, the DB2 index options contain the following composite option:
<using_block> : composite=yes
{
using vcat %s
using stogroup %s : category=storage, composite=yes
{
priqty %d : default=12
secqty %d
erase %s : default=no, list=yes | no
}

Defining physical options specified by a value


You can assign a value to a physical option in the edit field at the bottom of
the Physical Options dialog box (accessible from an object property sheet).
The Edit field is only active when you select an option in the right pane of the
dialog box which requires a value.
This edit field icon only be displayed when the following variables follow the
physical option name in the current DBMS definition.

Variable Description
%d Numeric value follows the physical option. You must enter a
numeric value in the edit field
%s String follows the physical option. You must enter a string in the edit
field

334
chapter 10 DBMS Definition Editor

The Options page for a table property sheet is shown below. When the
options pctthreshold is selected, the Value box appears next to the Equals
button.

Example In the Sybase Adaptive Server Enterprise 11 DBMS definition file the
max_rows_per_page is an index physical option. This option limits the
number of rows per data page. The Sybase syntax is the following:
with max_row_per_page = x
where x is the number of rows specified by the user.
This option is defined for the index object as follows:
with : composite=yes, separator=yes, parenthesis=no
{
max_rows_per_page=%d : default=0
fillfactor=%d : default=0
ignore_dup_key
sorted_data
<duprow> : list=ignore_dup_row | allow_dup_row
}
on %s : category=storage
The %d and %s variables are not currently checked by PowerDesigner.
Therefore it is possible to use %s for a numeric value.
The %d and %s variables must be at the last position and they must not be
followed by other options.
For example, the following syntax is wrong:
on %s with override

335
Using the DBMS Definition Editor

PowerDesigner only displays on %s.

How to define a default value for a physical option


You can give a default value to physical option by using the keyword
Default= to specify this value.
You define a default physical option value by adding a colon then default=x
(where x is the default value for the current DBMS) after the physical option
name, or after the %d or %s value.
For example, the default value for max_row_per_page is 0. In the Sybase
Adaptive Server Enterprise 11 DBMS definition, this default value for the
index object is defined as follows:
Option =
{
max_rows_per_page=%d : default=0
The default value is displayed by default in the Options page for an object.

How to define a list of values for a physical option


A physical option can correspond to a list of possible options. You can use
the keyword List= to specify a list.
You define a list of values for a physical option by adding a colon, then list=
x | y | z (where x, y and z are the possible values) after the physical option
name, or after the %d or %s value.
The values are separated by the | pipe character.
Example The <duprow> option of a Sybase Adaptive Server Enterprise index object
corresponds to two mutually exclusive options for creating a non-unique,
clustered index.
The syntax is:
[ignore_dup_row | allow_dup_row]
In the Sybase Adaptive Server Enterprise 11 DBMS definition file, this list is
defined as follows:
IndexOption =
<duprow> : list=ignore_dup_row | allow_dup_row
A dropdown listbox listing the values is displayed at the bottom of the
Options page for the object.
Note: If Default= and List= are used at the same time, they must be
separated by a comma.

336
chapter 10 DBMS Definition Editor

For example, if ignore_dup_row is the default value for an index, the syntax
used in the DBMS definition file to define this value is the following:
IndexOption =
<duprow> %s: default= ignore_dup_row, list=ignore_dup_row | allow_dup_row

The values defined in Default= and List= cannot be used with the %d or %s
variable. For example, the following syntax is not correct:
with %s: list= default fill factor percent %s | max_row_per_page %s

Defining a physical option corresponding to a tablespace or a storage


A physical option can use the tablespace code or the storage code:
category=tablespace or category=storage builds a list with all the tablespace
or storage codes defined in the List of Tablespaces or the List of Storages in
PowerDesigner.
For example, the on segmentname index option specifies that the index is to
be created on the named segment. A Sybase segment corresponds to a
PowerDesigner storage. The syntax is on segmentname.
In the Sybase Adaptive Server Enterprise 11 DBMS definition file, this
default value for the index object is defined as follows:
Option =
on %s: category=storage
A dropdown listbox listing the storages appears at the bottom of the Options
page for the object.

User interface impacts


The Option parameters defined for an object in the DBMS definition have the
following impacts on the PowerDesigner interface:
Tablespace and If the Tablespace or Storage Option parameter in the DBMS definition is
storage empty (has no physical options for an object), there is no corresponding
Options tab in the object property sheet.
For example, if the DBMS definition contains the following empty parameter
for a tablespace
Option=
then the tablespace option does not appear in the options page for any object.
Table and index If the Option parameters for Table or Index is empty, the Physical Options
checkbox in the Generate Database and Modify Database dialog boxes, are
grayed. In addition there is no corresponding Option tab in the table or index
property sheets.

337
Using the DBMS Definition Editor

Database If the Option parameter for the Database object is empty, the Physical
Options checkbox on the Database page of Generate Database dialog box is
grayed.
Pkey and key If the Option parameter for the objects Pkey and Key are empty, there is no
corresponding Options tab in object property sheet.

338
A P P E N D I X

Variables in PowerDesigner

About this chapter This chapter presents the variables that are available in PowerDesigner.
These variables can be used for database generation, trigger and procedure
generation, and reverse engineering.
Contents
Topic Page

List of PowerDesigner variables 340


List of PowerDesigner formatting variables 351

339
List of PowerDesigner variables

List of PowerDesigner variables


Many objects have both a code variable and a generated code variable.
The code variable is the attribute code that is defined in the object property
sheet.
The generated code variable is computed from the attribute code according to
avaivlable generation options. The values for the code and generated code
variables can be different in the following situations:
♦ When the Code is a reserved word or it contains invalid characters, the
generated code is quoted
♦ When the code is longer than authorized by the database, the generated
code is truncated

Common variables The following variables can be used for all named object definitions:
for all named
objects Variable name Comment
@OBJTNAME Object name
@OBJTCODE Object code
@OBJTLABL Object comment
@OBJTDESC Object desciption

Common variables The following variables can be used in all object definitions:
for objects
Variable name Comment
COMMENT Object comment. If no comment is defined the object name is
used
OWNER Generated code of the object owner, or the object parent
DBPREFIX Database prefix of object (name of database + ’.’ if database
defined)
QUALIFIER Whole object qualifier (database prefix + owner prefix)
OPTIONS SQL text defining physical options for object
CONSTNAME Object constraint name
CONSTRAINT Object constraint SQL body. For example(A <= 0) AND (A
>= 10)
RULES Concatenation of server expression for business rule
associated with object

340
Appendix Variables in PowerDesigner

Table variables The following variables can used in a table definition:

Variable name Comment


TABLE Generated code of the table
TNAME Table name
TCODE Table code
TLABL Table comment
PKEYCOLUMNS List of primary key columns. For exampleA, B
TABLDEFN Complete body of the table definition. It contains definition
of columns, checks and keys

Variables for The following variables can be used in domain check parameter and column
domain and check parameter definitions:
column checks
Variable name Comment
UNIT Standard check unit attribute
FORMAT Standard check format attribute
DATATYPE Data type. For example int, char(10) or numeric(8, 2)
DTTPCODE Data type code. For example int, char or numeric
LENGTH Data type length. For example 0, 10 or 8
PREC Data type precision. For example 0, 0 or 2
ISRDONLY TRUE if the read-only attribute of standard check is selected
DEFAULT Default value
MINVAL Minimum value
MAXVAL Maximum value
VALUES List of values. For example(0, 1, 2, 3, 4, 5)
LISTVAL SQL constraint associated with a list of values. For example
C1 in (0, 1, 2, 3, 4, 5)
MINMAX SQL constraint associated with minimum and maximum
values. For example(C1 <= 0) AND (C1 >= 5)
ISMAND TRUE if the domain or column is mandatory
MAND Contains the keywords "null" or "not null" depending on if
the attribute is mandatory or not mandatory
NULL Contains keyword "null" if the domain or column is not
mandatory

341
List of PowerDesigner variables

Variable name Comment


NOTNULL Contains Keyword "not null" if the domain or column is
mandatory
IDENTITY Keyword "identity" if the domain or column is identity
(Sybase specific)
WITHDEFAULT Keyword "with default" if the domain or column is with
default
ISUPPERVAL TRUE if the upper-case attribute of standard check is
selected
ISLOWERVAL TRUE if the lower-case attribute of standard check is selected

Column variables The following variables can be used in a column definition:

Variable name Comment


COLUMN Generated code of the column
COLNNO Position of Column in List of columns of Table
COLNNAME Column name
COLNCODE Column code
PRIMARY Contains Keyword "primary" if the column is a primary key
column
ISPKEY TRUE if the column is part of a primary key
FOREIGN TRUE if the column is part of a foreign key

342
Appendix Variables in PowerDesigner

Abstract data type The following variables can be used in an aabstract data type definition:
variables
Variable name Comment
ADT Generated code of the abstract data type
TYPE Type of Abstract data type. For example "array", or "list"
SIZE Abstract data type size
ISARRAY TRUE if the abstract data type is of type array
ISLIST TRUE if the abstract data type is of type list
ISSTRUCT TRUE if the abstract data type is of type structure
ISOBJECT TRUE if the abstract data type is of type object
ISJAVA TRUE if the abstract data type is of type JAVA class
ADTDEF Contains definition of the abstract data type

Abstract data type The following variable can be used in an abstract data type attribute
attribute variables definition:

Variable name Comment


ADTATTR Generated code of an abstract data type attribute

Domain variables The following variable can be used in a domain definition:

Variable name Comment


DOMAIN Generated code of a domain (also available for columns)

Business rule The following variables can be used in a business rule definition:
variables
Variable name Comment
RULE Generated code of a business rule
RULENAME Rule name
RULECODE Rule code
RULECEXPR Rule client expression
RULESEXPR Rule server expression

343
List of PowerDesigner variables

Index variables The following variables can be used in an index definition:

Variable name Comment


INDEX Generated code of the index
INDEXNAME Index name
INDEXCODE Index code
UNIQUE Contains keyword "unique" when an index is unique
INDEXTYPE Contains the index type (DBMS dependant)
CIDXLIST List of index columns. For example A asc, B desc, C asc
INDEXKEY Contains keywords "primary", "unique" or "foreign"
depending on an index origin
CLUSTER Contains keyword "cluster" when an index is a cluster index
INDXDEF Index definition (list of columns)

Index column The following variables can be used in index column definitions:
variables
Variable name Comment
ASC Contains keywords "ASC" or "DESC" depending on the sort
order
ISASC TRUE if the index column sort is ascending

Reference The following variables can be used in a reference definition:


variables
Variable name Comment
REFR Generated code of the reference
PARENT Generated code of the parent table
PNAME Parent table name
PCODE Parent table name
PQUALIFIER Parent table qualifier. See also QUALIFIER
CHILD Generated code of a child table
CNAME Child table name
CCODE Child table code
CQUALIFIER Child table qualifier. See also QUALIFIER
REFRNAME Reference name

344
Appendix Variables in PowerDesigner

Variable name Comment


REFRCODE Reference code
FKCONSTRAINT Foreign key (reference) constraint name
PKCONSTRAINT Constraint name of the primary key used to reference the
object
CKEYCOLUMNS List of parent key columns. For example C1, C2, C3
FKEYCOLUMNS List of child foreign key columns. For example C1, C2, C3
UPDCONST Update declarative constraint. This can be any of the
following keywords
Restrict
Cascade
Set null
Set default
DELCONST Delete declarative constraint. This can be any of the
following keywords
Restrict
Cascade
Set null
Set default
MINCARD Minimum cardinality
MAXCARD Maximum cardinality
POWNER Parent table owner name
COWNER Child table owner name
CHCKONCMMT TRUE when check on commit is selected on a reference
(ASA 6.0 specific)
JOINS Reference joins

Reference column The following variables can be used in reference column definitions:
variables
Variable name Comment
CKEYCOLUMN Generated code of the parent table column (primary key)
FKEYCOLUMN Generated code of a child table column (foreign key)
PK Generated code of a primary key column
PKNAME Primary key column name
FK Generated code of a foreign key column
FKNAME Foreign key column name

345
List of PowerDesigner variables

Variable name Comment


AK Alternate key column code (same as PK)
AKNAME Alternate key column name (same as PKNAME)
COLTYPE Primary key column data type
DEFAULT Foreign key column default value

Key variables The following variables can be used in a key definition:

Variable name Comment


COLUMNS List of key columns. For example"A, B, C"
ISPKEY TRUE when a key is the primary key for the table
PKEY Primary key constraint name
AKEY Alternate key constraint name
KEY Key constraint name

Variables for views The following variables can be used in a view definition:

Variable name Comment


VIEW Generated code of the view
VIEWNAME View name
VIEWCODE View code
VIEWCOLN List of columns of a view. For example"A, B, C"
SQL SQL text of a view. For example Select * from T1
VIEWCHECK Contains the keyword "with check option" if this option is
selected in the view property sheet
SCRIPT Complete view creation order. For example create view V1
as select * from T1

346
Appendix Variables in PowerDesigner

Trigger variables The variables listed below can be used in a trigger definition. You can also
use parent table variables in a trigger definition.

Variable name Comment


ORDER Order number of Trigger (where the current DBMS
supports more than one trigger of one type)
TRIGGER Generated code of the trigger
TRGTYPE Trigger type using keywords for each trigger type, for
example "BeforeInsert", or "AfterUpdate"
TRGEVENT Trigger event using keywords for each rigger event, for
example" Insert", "Update", and "Delete"
TRGTIME Timing of trigger using the keywords "Null", "Before", and
"After"
REFNO Reference order number in the list of references for the
table
ERRNO Error number for standard error
ERRMSG Error message for standard error
MSGTAB Name of a table containing user-defined error messages
MSGNO Name of a column containing error numbers in a user-
defined error table
MSGTXT Name of a column containing error messages in a user-
defined error table
SCRIPT SQL script of trigger or procedure.
TRGBODY Trigger body (only for Oracle ODBC reverse engineering)
TRGDESC Trigger description (only for Oracle ODBC reverse
engineering)

Database, trigger, The following variables can be used for database, procedure, and trigger
and procedure generation:
generation
variables Variable name Comment
DATE Generation date & time
USER Login name of the user executing the generation
PATHSCRIPT Path where the file script will be generated
NAMESCRIPT Name of the file script where SQL orders will be written
STARTCMD Description explaining how to execute a generated script

347
List of PowerDesigner variables

Variable name Comment


ISUPPER TRUE if upper case generation option is set
ISLOWER TRUE if lower case generation option is set
DBMSNAME Name of the DBMS associated with the generated model
DATABASE Code of the database associated with the generated model

Reverse The following variables can be used when reverse engineering a database
engineering into a PDM:
variables
Variable name Comment
R Set to TRUE during reverse engineering
S Allows to skip a word. The string is parsed for reverse
engineering but is not generated
D Allows to skip a numeric value. The numeric value is parsed
for reverse engineering but is not generated
A Allows to skip all text. The text is parsed for reverse
engineering but is not generated
ISODBCUSER True if the current user is the connected user
CATALOG Catalog name that will be used in ODBC reverse engineering
queries
SCHEMA Schema that will be used in ODBC reverse engineering
queries
SIZE Data type size of a column or a domain. Used for ODBC
reverse engineering, when a data type length is not defined in
the system tables

348
Appendix Variables in PowerDesigner

Database The following variables can be used for database generation when
synchronization synchronizing a modified PDM with an existing database:
variables
Variable name Comment
OLDOWNER Old owner name of the object. See also OWNER
NEWOWNER New owner name of the object. See also OWNER
OLDQUALIFIER Old qualifier of the object. See also QUALIFIER
NEWQUALIFIER New qualifier for the object. See also QUALIFIER
OLDTABL Old code of the table
NEWTABL New code of the table
OLDCOLN Old code of the column
NEWCOLN New code of the column

Metadata variables The following metadata variables are available:

Variable name Comment


@CLSSNAME Localized name for an object class. For example Table,
View, Column, Index
@CLSSCODE Object class code. For example TABL, VIEW, COLN,
INDX

DBMS, database The following DBMS and database options variables are available:
options variables
Variable name Comment
TABLESPACE Generated code of a tablespace
STORAGE Generated code of a storage

Variables for ASE The following DBMS specific variables are available for Sybase Adaptive
& SQL Server Server Anywhere and Microsoft SQL Server:

Variable name Comment


RULENAME Name of a business rule object associated with a domain
DEFAULTNAME Name of a default object associated with a domain

349
List of PowerDesigner variables

Procedure The following variables are can be used in a procedure definition:


variables
Variable name Comment
PROC Generated code of a procedure (also available for trigger
when a trigger is implemented with a procedure)
FUNC Generated code of a procedure where the procedure is a
function (with a return value)

350
Appendix Variables in PowerDesigner

List of PowerDesigner formatting variables


Variables have a syntax that can force a format on their values, as follows:
♦ Force values to lower-case or upper-case characters
♦ Truncate the length of values
When a variable does not specify formatting, its values have the same format
as in the PDM.

Format code Format of variable value in script


.L Lower-case characters
.T Removes blank spaces
.U Upper-case characters
.n Maximum length where n is the number of characters
n Justifies to fixed length where n is the number of characters
-n Right justify variable text to fixed length where n is the number
of characters

You embed formatting options in variable syntax as follows:


%.format:variable%
For example:
%.L:TABLE%
The table below shows formatted variables and their results in a script for the
table EMPLOYEE.

Template statement with variable Resulting script statement


create trigger %TABLE% create trigger EMPLOYEE
create trigger %.L:TABLE% create trigger employee
create trigger %.U:TABLE% create trigger EMPLOYEE
create trigger %.4:TABLE% create trigger EMPL
create trigger %.4L:TABLE% create trigger empl

351
List of PowerDesigner formatting variables

352
Glossary

abstract data type User defined data type which encapsulates a range of data values and
(ADT) functions. The functions are both defined on, and operate on the set of values

alternate key Column or columns whose values uniquely identify a row in the table and are
not primary key columns

business rule Written statement specifying what the information system must do or how it
must be structured to support business needs

clustered index Index in which the physical order and the logical (indexed) order is the same

column Data structure that contains an individual data item within a row (record),
model equivalent of a database field

Conceptual Data Entity-relationship diagram that models the information system without
Model (CDM) considering the details of physical implementation

constraint Named check that enforces data requirements, default values, or referential
integrity on a table or a column

data source Identification of the data to access, its operating system, DBMS, and network
platform

DBMS Text file in XML format that contains all the SQL syntax and specifications
for a Database Management System.

353
Glossary

Set of values for which a data item is valid


domain

foreign key Column or columns whose values depend on and migrate from a primary key,
or an alternate key, in another table

index Data structure that is based on a key and that speeds access to data and
controls unique values

ODBC Open Database Connectivity (ODBC) interface which gives PowerDesigner


access to data in database management systems (DBMS)

ODBC driver Part of the Open Database Connectivity (ODBC) interface that processes
ODBC functions calls, submits SQL requests to a specific data source, and
returns results to the application

Physical Data Table-reference diagram that models the information system including the
Model (PDM) details of physical implementation

primary key Column or columns whose values uniquely identify a row in a table

property sheet Window that displays the properties of an object

reference Link between a parent table and a child table. A reference can link tables by
shared keys or by specified columns.

referential integrity Rules governing data consistency, specifically the relationships among
primary keys and foreign keys of different tables

storage Named partition that stores tables and indexes on a storage device

table Collection of rows (records) that have associated columns (fields)

tablespace Named partition that stores tables and indexes in a database

354
Glossary

trigger Special form of stored procedure that goes into effect when you insert, delete,
or update a specified table or column

user Name that identifies a person or group working with objects in a PDM, and
which has the ability to own other objects in the PDM

unique index Index in which no two rows can have the same index value, including NULL

view Alternate way of looking at the data in one or more tables. Usually created as
a subset of columns from one or more tables

355
Glossary

356
Index

apply
business rule 20, 132
validation rule 132
A archive
abstract data type 353 PDM 271
attribute variable 343 syncronize generation 274
categories 47 ASK
create 49, 264 column default 59
define 47 assign
drop 264 alias to column 120
link to Java class 51 alias to table 120
property 49 attach
use in PowerDesigner 48 object to user 141
variable 343 automatic
access correct 152
database 245 error correction 151
Java class 55 rebuild triggers 171
trigger property 177 trigger creation 171
Adaptive Server Anywhere automatic archive
variable 349 merge models 163
add auto-migrate 71
column 65 check parameter 71
column to key 71 column 80
template item to trigger template 187 default join 84
ADT See abstract data type domain 71
AKCOLN 218 foreign key 8
ALLCOL 218 validation rule 71
alter auto-reuse
script 273 column 80
alternate key 3, 353
column 73
constraint 74, 76
define 69 B
designate 73 begin
display 31 script 255, 258, 260, 262, 263
generate 260, 261 bend
generate index 106 reference 98
index 100, 101, 103, 262 binary
list 29 data type 41, 285
name 73 bitmap
number 32, 76 data type 41, 285
physical option 261 boolean
variable 76 data type 40, 283

357
Browser referenced table 87
create domain 36 target database 245
create table 26 character
build format 228, 264, 273
index 106 script 228, 264, 273
reference 89 check
business rule 16, 17, 353 model See check model
apply 20, 132 check model
CDM 16, 17 automatic correction 145
create 18 correct 150
definition 18 correct manually 151
domain 44 global model 146, 147
expression 21, 132 option 145, 147
fact 18 package 146
formula 18 parameters verified 144
PDM 16, 17 PDM 143, 147, 150, 151
property 17 select object 146
type 18 set error severity 145
use in PDM 20 check parameter
validation 18, 132, 260, 261, 263 additional 131
variable 343 auto-migrate 71
byte column 66, 129, 132, 261
data type 40, 283 constraint 30, 66
data type 61
define 129
domain 44, 129, 132
C generate 260, 261, 263
cardinality property 129
format 93 standard 129
maximum 92 table 30, 260
minimum 92 type 129
reference 92, 96, 97 validation 132
referential integrity 92 validation rule 16, 17, 129
category child
DBMS 313 table 75
CDM 353 child table
data type 283, 328 change 87
generate 286, 287 choose
generate from package 288 DBMS 316
generate from PDM 288 clause
generation option 287 insert 121
global model 288 clear
modify 286 index 106
select object for generation 288 client
update 286, 291 business rule 21
CDM objects expression 21, 132
translate to PDM 282 close
change database 263
foreign key column 86 PDM 6
reference end 87 cluster

358
index 100, 101 value 329
CODASYL 99 variable 132, 221, 342
code view 115, 127
display 31 COLUMN
option define 79 ConstName 324
package 12 command
preference 31 storage 250, 253
reference 79 tablespace 250, 253
unique 79 comment
variable 323 column 261
column 3, 353 package 12
add 65 script 228, 264, 273
add to key 71 table 260
alias assign 120 view 261
alternate key 73 composite
attach domain 63 physical option 332
auto-migrate 80 configure
auto-reuse 80 data source 242
check parameter 129, 132, 261 storage 250
check parameter variable 341 tablespace 250
comment 261 confirm
constraint 66 delete 8
create 60, 65, 260, 261 connect
data type 31, 61, 127, 329 data source 243
default 59 database 244, 248, 249
define 58, 60 ConstName
display 31 COLUMN 324
domain 44 common name variable 323
domain coherence 44 KEY 324
duplicate 65 PKEY 324
enforce coherence 6 REFR 325
foreign key 59, 70 TABLE 323
generate 260, 261 constraint 353
identity 31, 59 alternate key 74, 76
indicator 31 column 66
link to key 85 delete 93, 203
list 29, 67 foreign key 74, 75
mandatory 66 generate 73
migrate 85 link index 103
non-divergence from domain 44 name 30, 66, 74, 75, 76, 322
null 31 primary key 74
optional 66 table 30
primary key 59, 70 template 322
property 59 unique 73
remove from index 105 update 93, 203
reuse 85 variable 323, 324, 325
sort 67 constraint name
table 29, 31 default 75, 76
update 7 display 96
validation rule 132, 261 filter 73

359
label 96 function 215, 216
copy procedure 215, 216
DBMS 316 script 255, 258, 260, 263
correct
automatic 145, 151, 152
check model 150
error 145 D
manual 151 data source 353
PDM 150, 152 configure 242
create connect 243
abstract data type 49, 264 define 241
business rule 18 disconnect 244
column 60, 65, 260, 261 synchronize generation 276
data type 263 data type 37, 40
database 11, 255, 260, 263, 268, 269 binary 41, 285
database script 274, 276, 279 bitmap 41, 285
DBMS 316 boolean 40, 283
domain 36 byte 40, 283
empty view 113 character 41
error message 234 column 31, 61, 127, 329
function 216 conceptual 283
index 101, 260 create 263
join 84 date 41, 284
message table 234 DBMS 328
new template item 208, 210 decimal 40, 283
parameter 260, 261, 263 default 8
PDM 2, 4 define 328
procedure 216, 228 display 31
reference 82 domain 38, 39, 40, 43, 44, 329
storage 263 drop 263
table 25, 255, 260 float 40, 283
table from Browser 26 generate 263
table in diagram 25 image 41, 285
table in list 26 integer 40, 283
tablespace 263 length 37, 40
template item 205 money 40, 283
temporary table 272 number 40, 283
trigger 168, 228, 231, 233 OLE 41, 285
trigger automatically 171 OOM 301
trigger manually 175 precision 37, 40
trigger template 187, 189, 192, 193 select 38, 61
user 141 serial 40, 283
user define index 102 time 41, 284
user-defined trigger 175 translate 283, 328
user-defined trigger template 193, 194 undefined 38, 40, 41, 43, 61, 285
view 111, 260, 261 user-defined 263
Creation script view 127
syncronize generation 279 database
customize access 245
DBMS 319 change 245

360
close 263 function template 322
connect 244, 248, 249 general 313
create 11, 255, 260, 263, 268, 269 import 316, 318
create script 255, 263 keyword 329
create trigger 233 library 4
creation script 166 link 4
define 10 list 316
display 244, 248, 249 local to the model 4
drop 263 modify 319
generate 255, 260, 263, 268, 269, 273 new 316
generate PDM 161, 162 option 322, 331
information 244 overview 312
modify 260, 272, 273, 274, 276, 279 physical option 136, 332
open 263 procedure template 322
options variable 349 property 316
owner 140 save 318
parameter 272 script 313
physical option 263 select 316
preserve data parameters 272 template 322
preserve object 245 trigger template 183, 322
property 10 variable 322
script 268, 273 decimal
select 245 data type 40, 283
select object for generation 266 declare
syncronization variable 349 referential integrity 265
syncronize archive PDM 274 template item 213
syncronize creation script 279 DEF
syncronize ODBC data source 276 import from PowerDesigner 6 318
target 245 default
user 140 column 59
variable 347 constraint name 75, 76
Datacom physical option 136, 336
column default 59 define
date abstract data type 47
data type 41, 284 alternate key 69
DB2 check parameter 129
column default 59 code option 79
DBMS 353 column 58, 60
categories 313 constraint name 322
choose 316 data source 241
copy 316 data type 328
create 316 database 10
create from list 316 DBMS 312
customize 319 default physical option 336
data type 328 domain 35, 36
define 312, 316 foreign key 69
definition editor 312 function 215
edit 312 index 100
field 313 join 84, 85
format 322 key 69

361
keyword 329 primary key 31
list of physical option values 336 query 125
option 331 reference 96, 97, 98, 99
PDM 4 referential integrity 96
PDM options 6 SQL 125
physical option 135, 332 table 31
primary key 69 view 127
procedure 215, 216 warning message 149
reference 77, 82 diverge
referential integrity 94 from domain 6
storage 251 domain 354
table 24 access list 36
tablespace 251 attach column 63
template 322 auto-migrate 71
template item 168, 200 business rule 44
trigger 168 check parameter 44, 129, 132
trigger template 168 check parameter variable 341
validation rule 134 coherence 44
view 110 column 44
view query 115 create 36
DEFINE 219 create from Browser 36
DEFINEIF 220 data type 37, 38, 39, 40, 43, 44, 329
definition define 35, 36
business rule 18 diverge from 6
delete enforce 8, 44
confirm 8 enforce coherence 6
constraint 93, 203 length 37, 40
index 109 mandatory 44
reference 89 modify 43
trigger template 185 non-divergence 44
detach precision 37, 40
PDM from workspace 6 property 35
diagram use 44
create table 25 validation rule 132
insert table symbol 25 value 329
disconnect variable 132, 343
data source 244 drag
display reference 98
alternate key 31 drop
code 31 abstract data type 264
column 31 data type 263
constraint name 96 database 263
data 248, 249 foreign key 262
data type 31 index 262
database information 244 join index 262
error message 149 primary key 261
index 31 storage 263
index number 31 table 260
key number 31 tablespace 263
name 31 temporary table 272

362
view 261 owner 161
duplicate qualifier 161
column 65 reverse engineer 161
FKCOLN 220
float
data type 40, 283
E FOREACH_CHILD 221
edit FOREACH_COLUMN 222
DBMS 312 FOREACH_PARENT 223
function 216 foreign key 3, 354
procedure 216 auto-migrate 8, 71
script 255, 258 change column 86
trigger 177 column 59, 70
end constraint 74, 75
script 255, 258, 260, 262, 263 define 69
enforce designate 70
domain 44 drop 262
non-divergence 44 generate 260, 262, 298
error generate index 106
check model 145 index 100, 101, 103, 262
ERROR 220 name 101, 298
error message 220 number 32, 33
display 149 referential integrity 91
parameter 229 variable 75, 225
PDM 145, 147, 150, 151 foreign key index 298
user-defined 234, 235 format
ERwin cardinalty 93
import 154 character 228, 264, 273
example DBMS 322
procedure 199 script 228, 264, 273
trigger template 199 variable 171, 187, 204, 259, 326, 351
execute formula
query 249 business rule 18
export view 127
PowerDesigner 6 156 function
expression create 216
business rule 21, 132 custom 215, 216
client 21, 132 DBMS 322
server 21, 132 define 215
function insert 216
macro insert 216
operator insert 216
F template 215
fact variable insert 216
business rule 18
field
DBMS 313
fiilter G
constraint name 73 general
filter DBMS 313

363
generate
alternate key 260, 261
H
HAVING
alternate key index 106
insert in query 123
CDM 286, 287, 288
CDM from PDM 288
check parameter 260, 261, 263
column 260, 261 I
constraint 73 identify
data type 263 template item 202
database 255, 260, 263, 268, 269, 273 trigger template 184
error message 234, 235 identity 31
foreign key 260, 262, 298 column 59
foreign key index 106 SQL Server 59
index 73, 106, 260, 261, 262 Sybase 59
join index 261, 262 image
key 261 data type 41, 285
modified database 272, 274, 276, 279 implement
new OOM 302 trigger referential integruty 173
new PDM 286, 295 import
OOM 302, 303, 307 DBMS 316, 318
OOM object 300 DEF file 318
PDM 282, 295 ERwin 154
PDM from database 161, 162 model 154
PDM from script 166 PDM 154
PDM to OOM 304 INCOLN 223
physical option 260, 262, 263 index 3, 354
preserve data parameters 272 alternate key 100, 101, 262
primary key 260, 261, 298 clear 106
primary key index 106 cluster 100, 101
procedure 227 clustered 353
reference 89 column variable 344
referential integrity 91, 260, 264, 265 create 101, 102, 103, 260
script 228, 231, 260, 263, 264, 268, 273 define 100
select object 230, 265 delete 109
storage 263 display 31
table 260 drop 262
tablespace 263 drop join 262
trigger 227, 228, 231, 233, 265 foreign key 100, 101, 262, 298
validation rule 132, 260, 261, 263 generate 73, 106, 260, 261, 262
view 260, 261 key constraint 103
generated code link to key/reference 103
variable 323, 340 linked to key 101
global model list 29, 109
CDM 288 number 32
check 147 primary key 100, 101, 262, 298
check model 146 property 100
PDM 147 rebuild 106
rebuild index 107 rebuild from global model 107
GROUP BY rebuild from package 108
insert in query 123 rebuild option 106

364
remove column 105 reference 82, 96
table 31, 101 reuse column 85
types 101 JOIN 224
unique 73, 100, 101, 355 justify
user define 102 variable 171, 187, 204, 259, 326, 351
user-defined 101
variable 344
index number 32
display 31 K
indicate key
trigger order 180 add column 71
Ingres alternate 69
column default 59 define 69
insert foreign 69
clause 121 generate 261
GROUP BY in query 123 index 101
HAVING in query 123 link column 85
ORDER BY in query 124 primary 69
procedure in template 199 variable 346
table in list 26 KEY
table symbol 25 ConstName 324
trigger template 184, 199 key number
WHERE in query 122 alternate key 32
install display 31
java class 264 foreign key 32, 33
integer keyword
data type 40, 283 DBMS 329
interface default 329
impact of physical option value 337 define 329
physical option 334

J
Java L
link class 48 label
java class constraint name 96
remove 264 referential integrity 96
Java class link
access from PDM 55 DBMS 4
link 51 Java class 48, 55
reverse engineer 55 Object-Oriented Model 51
join reference 82
change child column 86 reverse Java class 48
create 84 list
default 84 alternate key 29
define 84, 85 arrange 29
index 262 column 29, 67
index generate 261, 262 create table 26
migrate column 85 DBMS 316
primary key 84 index 29, 109

365
order 29 table 27, 28
physical option 336 template item 211
reference 88 trigger 177
sort 67, 88 trigger from table 177
standard data types 39 trigger template 195
table 25, 28, 29 view 114
variable 171, 187, 204 money
LISTVAL data type 40, 283
check parameter 131 move
local reference to table 99
DBMS 4 multiple
trigger 180

M
macro N
trigger 218 name
trigger template 218 constraint 30, 74, 75, 76
variable 171, 187, 204 convention 198
manual display 31
create trigger 175 foreign key 298
message package 12
error 234 preference 31
metadata primary key 298
variable 349 reference 96
MINMAX trigger 198
check parameter 131 trigger template 188
mode variable 323
CODASYL 99 namespace
reference 98, 99 package 12
relational 99 new
model DBMS 316
ERwin 154 NMFCOL 225
import 154 non-divergence
script 255, 263 enforce 44
trigger template 184 number
model option 6 alternate key 76
column 6 data type 40, 283
domain 6 reference 75
modify
CDM 286
database 260, 272, 273, 274, 276, 279
DBMS 319 O
DBMS template item 212 object
DBMS trigger template 196 attach to user 141
domain property 43 owner 140
foreign key column 86 PDM 3
model trigger template 197, 213 Object-Oriented Model See OOM
PDM 282, 302 link 51
reference 98 link Java class 48

366
ODBC 161, 354 check model 146
administrator 241 code 12
archive PDM 276 comment 12
driver 354 generate CDM 288
interface 240 name 12
ODBC namespace 12
syncronize generation 276 property 12
OLE rebuild index 108
data type 41, 285 table 29
OOM See Object-Oriented Model Palette
data type 301 PDM tools 14
generate 302, 303 release tool 14
generate from PDM 304 select tool 14
generate object 300 parameter
generate option 302 create procedure 228
generate options 303 create trigger 228
generate update 307 error 229
generation options 302 generate CDM 286
modify 302 generate PDM 295
object 300 generate trigger 228
preserve 302 modify database 272
update 302 parent
open table 75
database 263 parent table
PDM 4 change 87
option PDM 354
check model 145, 147 archive 271
DBMS 322, 331 business rule 20
define 331 check 147, 151
define PDM 6 check model 143, 145, 150
physical 260, 262, 263 close 6
referential integrity 264, 265 correct 150, 152
reverse engineer 162 create 2, 4
script 228, 264, 273 data type 328
order define 4
trigger 180 detach from workspace 6
ORDER BY error 145, 147, 150, 151
insert in query 124 generate 282, 295
overview generate from database 161, 162
DBMS 312 generate from script 166
owner generation options 286, 295
define 140 graphic tools 14
table 140 import 154
using 140 modify 9, 282
view 140 object 3, 300
open 4
option 331
Palette 14
P preserve 282, 286
package property 9

367
role 2 constraint 74
save 6 define 69
update 282 designate 70
validate 143 display 31
verify 144 drop 261
warning 145, 147, 150, 151 generate 260, 261, 298
PDM objects generate index 106
translate to OOM 300 index 100, 101, 103, 262
physical option join 84
alternate key 261 name 101, 298
combine keywords 334 physical option 261
composite 332 referential integrity 91
DBMS 332 variable 74, 225
default 136 primary key index 298
default value 336 procedure
define 135, 332 create 216, 228
impact on interface 337 custom 215, 216
list of values 336 DBMS 322
primary key 261 define 215, 216
specify value 334 example 199
storage 136, 337 function insert 216
tablespace 136, 337 generate 227, 228
WITH 333 macro insert 216
PKCOLN 225 operator insert 216
PKEY parameter 228
ConstName 324 stored 215, 216
PowerDesigner 6 template 215, 322
export 156 trigger template 199
save as 156 user-defined 216
precision 37, 40 variable 347, 350
preference variable insert 216
code 31 property
name 31 abstract data type 49
reference 96, 98, 99 business rule 17
table 31 check parameter 129
view 127 column 59
preserve domain 35
CDM 286 index 100
data parameters 272 package 12
database object 245 reference 78
modification 282, 286, 302 referential integrity 92
OOM 302 table 24, 27
PDM 282 template item 204
preview trigger 170
SQL 13 trigger template 186
storage command 253 view 110, 114
tablespace command 253 property sheet 354
trigger 182 PDM 9
primary key 3, 354
column 59, 70

368
preference 96, 98, 99
Q property 78
query
rebuild 89
display 125
relational 99
execute 249
reuse column 80
SQL 249
select for view 118
syntax 125
sort 88
quotation mark
straighten 98
generate 134
text 96
unique code 8, 79
variable 75, 344
R view 115
rebuild referential integrity 91, 354
index 106 cardinality 92
reference 89 declarative 265
rebuild triggers define 94
create trigger automatically 171 delete 93
delete and rebuild 171 display 96
delete trigger 171 generate 91, 92, 260, 264, 265
insert trigger 171 implement by trigger 173
select trigger template 171 label 96
template item 171, 186 option 264, 265
trigger referential integrity 173 property 92
trigger template 171, 186 trigger 173, 265
update trigger 171 update 93
user-defined trigger 171 REFR
reference 3, 354 ConstName 325
auto-migration 80 relational mode 99
bend 98 remove
cardinality 92, 96, 97 column from index 105
change table 87 java class 264
child table 92 retrieve
CODASYL 99 WarehouseArchitect object 153
code 79 reverse
column variable 345 link Java class 48
create 82 reverse engineer
define 77, 82 automatic archive 163
delete 89 data source 160
display 96, 97, 98, 99 filter 161
drag 98 generate PDM from database 161, 162
generate 89 generate PDM from script 166
join 82, 96 Java class 55
link 82 merge models 162
list 88 option 162
mode 98, 99 owner filter 161
modify 98 qualifier filter 161
move to table 99 script file 160
name 96 variable 348
number 75 RULES
number of children 92 check parameter 131

369
reference 88
S specify
save
physical option value 334
as PowerDesigner 6 156
SQL
DBMS 318
clause 121
PDM 6
display 125
script
GROUP BY 123
alter 273
HAVING 123
begin 255, 258, 260, 262, 263
insert 121
comment 228, 264, 273
ORDER BY 124
create database 255, 268
preview 13
create table 255
query 125, 249
create trigger 231
syntax 125
customize 255, 258, 260, 263
view expression 122
database create 255, 263
WHERE 122
database creation 166
SQL Server
DBMS 313
identity 59
edit 255, 258
variable 349
end 255, 258, 260, 262, 263
SQLBase
format 228, 264, 273
column default 59
generate 228, 231, 260, 263, 264, 268, 273
standard data type
generate PDM 166
list 40
model 255, 263
standard data types
modify creation 274, 276, 279
list 39
modify database 273
storage 354
option 228, 264, 273
command 250, 253
preview 13
configure 250
table 258, 260
create 263
text color code 13
define 136, 251
title 228, 264, 273
drop 263
variable 255, 258
generate 263
select
physical option 337
column for view 115
preview 253
data type 38, 61
select 136
data type for domain 38, 39
straighten
DBMS 316
reference 98
generate objects 266
Sybase
object for check model 146
identity 59
object to generate 230, 265, 266
System 10 59
reference for view 115, 118
System 11 59
table for view 115
Sybase SQL Anywhere
target database 245
data type 283
serial
symbol
data type 40, 283
insert table 25
server
table 25
business rule 21
syncronize
expression 21, 132
archive PDM 274
sort
creation script file 279
column 67
database generation 272
list 67, 88
syntax

370
object compatibility 245 command 250, 253
physical option 332 configure 250
query 125 create 263
variable 171, 187, 204, 259, 326, 351 define 136, 251
drop 263
generate 263
physical option 337
T preview 253
table 3, 354 select 136
alias assign 120 template
alternate key 29, 73 constraint name 322
check parameter 260 DBMS 322
child 75 define 322
column 29, 31 template item 200
comment 260 add to trigger 178, 196
constraint 30 add to trigger template 187
create 25, 255, 260 create 205
create from Browser 26 create from existing template item 205, 208
create trigger 175 create new 208, 210
define 24 declare in trigger 213
delete index 109 define 168, 200
display 31 function 215
drop 260 identify 202
foreign key 70, 71 insert in trigger 201
generate 260 insert in trigger template 201
index 29, 31, 101 modify 211
insert in list 26 modify DBMS 212
list 25, 28, 29 procedure 215
message 234 property 204
modify 27, 28 rebuild triggers 186
modify trigger 177 trigger add 178, 196
owner 140 variable 204
package 29 text
parent 75 reference 96
physical option 260, 262 table 31
preference 31 view 127
primary key 70 time
property 24, 27 data type 41, 284
script 258, 260 title
select for view 115 script 228, 264, 273
symbol 25 tool
temporary create 272 release 14
temporary drop 272 select 14
text 31 translate
validation rule 260 data type 283, 328
variable 74, 75, 76, 341 PDM to OOM 301
view 115, 127 trigger 355
TABLE access property 177
ConstName 323 add template item 178, 196
tablespace 354 create 168, 228, 231, 233

371
create automatically 168, 171 macro 218
create manually 168, 175 model 184
create overview 169 modify 195
declare template item 213 modify DBMS 196
define 168 modify model 197, 213
edit 177 name 188, 198
function insert 177, 178, 195, 211 procedure 199
generate 227, 228, 231, 233, 265 property 186
insert template item 201 rebuild triggers 186
macro 218 template item 186
macro insert 177, 178, 195, 211 type 184
modify 177 update 185
modify from table 177 user-defined 184
multiple 180 variable 171, 187, 204
name convention 198
operator insert 177, 178, 195, 211
order 180
overview 168 U
overview in PowerDesigner 168 undefined
parameter 228 data type 38, 40, 43, 61
preview 182 unique
property 170 constraint 73
rebuild See rebuild triggers index 73, 100, 101
referential integrity 265 reference 8
same type 180 update
script 231 CDM 286, 291
template See trigger template column 7, 44
template item See template item constraint 93, 203
template item add 178, 196 OOM 302, 307
user-defined 175 PDM 282
variable 347 trigger template 185
variable insert 177, 178, 195, 211 user 355
trigger template 183 attach object 141
add template item 187 create 141
available to other models 169 define 140
copy 189, 193 user-defined
create 187, 193, 194 error message 234
create DBMS 189, 192 generate 235
create from duplicate 189, 193 index 101, 102
create from scratch 192 trigger template 184
create user-defined 193, 194
DBMS 183, 187, 322
declare template item 213
define 168, 193 V
delete 185 validate
duplicate 189, 193 PDM 143
example 199 validation
identify 184 business rule 18
insert 184, 199 validation rule 129
insert template item 201 apply 132

372
auto-migrate 71 table 74, 75, 76, 341
business rule 132 template item 171, 187, 204
check parameter 132 trigger 347
column 132, 261 trigger template 171, 187, 204
define 134 view 346
domain 132 verify
generate 132, 260, 261, 263 objects in PDM 144
table 260 PDM 144
value view 3, 355
specify physical option 334 column 115, 127
variable comment 261
procedure 347 create 111, 113, 260, 261
variable data type 127
abstract data type 343 DBMS field 313
abstract data type attribute 343 define 110
Adaptive Server Anywhere 349 define query 115
all named objects 340 display 127
all objects 340 drop 261
business rule 343 formula 127
code 323, 340 generate 260, 261
column 132, 221, 342 GROUP BY 123
column check parameter 341 HAVING 123
common 340 modify 114
constraint 323, 324, 325 ORDER BY 124
constraint name 74, 75, 76 owner 140
database 347 preference 127
database options 349 property 110, 114
database syncronization 349 reference 115
DBMS 322 select reference 118
domain 132, 343 select table 111, 115
domain check parameter 341 table 115, 127
foreign key 225 text 127
format 171, 187, 204, 259, 326, 351 variable 346
generated code 323, 340 WHERE 122
index 344
index column 344
justify 171, 187, 204, 259, 326, 351
key 346 W
list 171, 187, 204, 340 WAM See WarehouseArchitect
macro 171, 187, 204 WarehouseArchitect
metadata 349 retrieve object 153
name 323 warning
primary key 225 PDM 145, 147, 150, 151
procedure 350 warning message
reference 75, 344 display 149
reference column 345 WHERE
reverse engineer 348 insert in query 122
script 255, 258 WITH
SQL Server 349 physical option 333
syntax 171, 187, 204, 259, 326, 351

373
X
Xdb
column default 59

374

S-ar putea să vă placă și