Вы находитесь на странице: 1из 98

CHARONWARE

database design/modeling tools

CASE Studio 2
user's manual

written by: Vaclav Frolik

document version: 1.8


Created: 03/07/2006

CASE Studio 2 – manual http://www.casestudio.com 1/98


CHARONWARE
database design/modeling tools

Table of Contents
Introduction to CASE Studio 2 .................................................................................................................................4
CASE Studio 2 in brief..........................................................................................................................................4
Supported databases.............................................................................................................................................4
Desktop area description.....................................................................................................................................5
Toolbars - Files......................................................................................................................................................6
Hotkeys.................................................................................................................................................................9
Display modes....................................................................................................................................................10
Display levels......................................................................................................................................................10
Creating basic Entity relationship diagrams ............................................................................................................11
Selecting the target database..............................................................................................................................11
Creating new entities..........................................................................................................................................11
Adding new Attributes .......................................................................................................................................13
Creating relationships between entities.............................................................................................................15
Using the Rolename feature ..............................................................................................................................17
Connecting Parent and Child entities.................................................................................................................18
Displaying Partiality.............................................................................................................................................20
Defining Cardinality............................................................................................................................................21
Setting up Referential integrity rules...................................................................................................................22
Understanding Foreign keys...............................................................................................................................23
Foreign keys mapping (how to create a compound foreign key).......................................................................24
Imported foreign keys.........................................................................................................................................25
Specifying relationship properties.......................................................................................................................26
Advanced database design ......................................................................................................................................27
Defining Advanced options – Entity....................................................................................................................27
Defining Advanced options – Attribute..............................................................................................................28
Using the ”Empty” data type..............................................................................................................................29
Using the Dictionary...........................................................................................................................................29
Creating and using Standard Dictionary Items...................................................................................................30
Creating and using User Defined Data Types.....................................................................................................32
Creating indexes.................................................................................................................................................35
Creating alternate keys.......................................................................................................................................36
Working with Triggers, Views, Stored procedures.............................................................................................37
Permanent Text objects......................................................................................................................................38
Database dependent Text objects......................................................................................................................38
Creating Text objects..........................................................................................................................................38
Creating patterns for Text objects......................................................................................................................39
Creating user roles and specifying user permissions..........................................................................................40
Database Rights and Permissions........................................................................................................................41
Using the Model verification feature........................................................................................................................42
Verifying models.................................................................................................................................................42
Accessing verification..........................................................................................................................................42
Using submodels .....................................................................................................................................................43
Creating submodels............................................................................................................................................43
Erasing submodels..............................................................................................................................................44
Removing / Erasing entities from submodels......................................................................................................44
Hiding relationship lines......................................................................................................................................45
SQL/DDL script generating......................................................................................................................................46
Selecting items....................................................................................................................................................46
Selecting a method.............................................................................................................................................47
Setting Advanced options...................................................................................................................................48
Selecting submodels............................................................................................................................................48
Creating Alter scripts..........................................................................................................................................53

CASE Studio 2 – manual http://www.casestudio.com 2/98


CHARONWARE
database design/modeling tools

Generating HTML/RTF reports, exporting diagrams..............................................................................................54


Creating documentation.....................................................................................................................................54
Selecting output and generating reports.............................................................................................................55
Changing the diagrams' look and saving models......................................................................................................57
Setting background colors and fonts ..................................................................................................................57
Displaying relationship lines and names..............................................................................................................57
Adding break-points to relationship lines...........................................................................................................58
Removing break-points from relationship lines..................................................................................................58
Moving relationship lines....................................................................................................................................59
Moving entities....................................................................................................................................................59
Displaying entities...............................................................................................................................................60
Saving models.....................................................................................................................................................60
Reverse Engineering.................................................................................................................................................61
Using the Universal Reverse Engineering...........................................................................................................61
Selecting a database............................................................................................................................................62
Connecting to a database...................................................................................................................................62
Selecting items....................................................................................................................................................63
Selecting tables...................................................................................................................................................63
Saving settings as Aliases.....................................................................................................................................64
Using the Layout feature.....................................................................................................................................64
Reversing unsupported databases via ADO........................................................................................................64
Reversing older databases ..................................................................................................................................64
Maintaining Models..................................................................................................................................................65
Using the Gallery................................................................................................................................................65
Using the Model explorer...................................................................................................................................66
Working with a To-Do list...................................................................................................................................67
Automatic model conversion..............................................................................................................................69
Using the Version manager......................................................................................................................................71
Creating a project...............................................................................................................................................71
Comparing versions............................................................................................................................................72
Generating HTML/RTF reports..........................................................................................................................73
Configuration...........................................................................................................................................................74
Environment setup.............................................................................................................................................74
Model properties................................................................................................................................................76
Extended settings................................................................................................................................................77
Extending CASE Studio 2.........................................................................................................................................78
Using the Templates Editor.................................................................................................................................78
Introduction to the Templates Editor's interface................................................................................................79
Templates - sections explanation........................................................................................................................79
Importing templates............................................................................................................................................80
Modifying templates............................................................................................................................................81
Creating user defined templates.........................................................................................................................82
Creating new Variables.......................................................................................................................................86
Exporting templates and creating packages........................................................................................................89
Publishing packages.............................................................................................................................................89
Deleting packages...............................................................................................................................................89
Using the MS Scripting window .........................................................................................................................90
Appendix A - Normal Forms ..................................................................................................................................91
Notes:.................................................................................................................................................................94
Links....................................................................................................................................................................97
Acknowledgments..............................................................................................................................................98

CASE Studio 2 – manual http://www.casestudio.com 3/98


CHARONWARE
database design/modeling tools

Introduction to CASE Studio 2

CASE Studio 2 in brief


CASE Studio 2 is a database modeling and reporting tool. Main features include: Entity
Relationship Diagrams (ERD), Data Flow Diagrams (DFD), Generating SQL scripts, Reverse
engineering (RE), generating very detailed documentation and other very useful features.
When creating ER Diagrams the program considers individual database options such as
referential integrity, constraints, domains, triggers, etc. The software allows you to define all
of an attributes' values, the types of relationships and other criteria, as for example indexes,
unique keys etc. More information about the software can be found at:

http://www.casestudio.com

Supported databases
CASE Studio 2 supports more than 30 database systems including the following:

• Advantage DS 8, 7
• Access 2000
• Access 97
• Clipper 5
• DBIsam 3.23
• DB2 UDB ver. 8
• DB2 UDB ver. 7
• Firebird 1.5
• Informix 10
• Informix 9
• Ingres
• InterBase 7 (incl. 7.5)
• InterBase 6 SQL 3
• InterBase 6 SQL 1
• InterBase 5 and InterBase 4
• MaxDB 7.6 (formerly known as SAP DB)
• MS SQL 2005, 2000
• MS SQL 7
• MS SQL 6.5
• MySQL 5.0
• MySQL 4.1 (also 4.1.14), 4.0
• MySQL 3.23
• Oracle 10g (also Release 2), Oracle 9i (also Release 2), Oracle 8
• Paradox
• Pervasive v9
• Pervasive V8
• PostgreSQL 8.1, 8.0, PostgreSQL 7.4 and PostgreSQL 7.3
• Sybase Anywhere 9
• Sybase ASE 15, 12.5.3, Sybase ASE 12.5.2., 12.5.1 and 12.5

CASE Studio 2 – manual http://www.casestudio.com 4/98


CHARONWARE
database design/modeling tools

Desktop area description

The CASE Studio 2 product includes a full featured graphical user interface. Opening CASE
Studio 2 displays command menus across the top of the window, opening a new document
displays the Overview Tree on the left side of the screen and the Entity Relationship
diagram on the right side.

The Desktop area on the right side is used to add entities with attributes and relationships.
Notes and a drawing stamp can also be added. Other elements, such as views, triggers,
stored procedures etc. are stored in the appropriate sections of the software.

CASE Studio 2 – manual http://www.casestudio.com 5/98


CHARONWARE
database design/modeling tools

Toolbars - Files

- opens the Target Database Selection dialog


- opens an existing model
- opens a list of recently opened models
- saves a model immediately
- opens the Print dialog
- opens the Environment Setup dialog
- opens the Model Explorer
- opens the Model Check dialog
- opens the Generate SQL dialog
- opens the Model properties dialog
- opens the Dictionary

ERD objects

- allows you to make a selection


- adds an entity to a model
- adds an identifying relationship to a model
- adds a non-identifying relationship to a model
- adds a M:N relationship to a model
- adds an informative relationship to a model
- adds a Note to a model
- adds a Stamp to a model

TIP: Hold down the Shift key and click any icon on the ERD objects menu to place a series
of Entities, Relationships etc.

CASE Studio 2 – manual http://www.casestudio.com 6/98


CHARONWARE
database design/modeling tools

Display mode

- sets the display level to „Entity“


- sets the display level to „Primary keys“
- sets the display level to „Keys“
- sets the display level to all „Attributes“
- switches between the Logical and Physical view modes
- shows/hides indexes

DFD objects

- allows you to make a selection


- adds a Data store to a Data flow diagram
- adds a Terminator to a Data flow diagram
- adds a Process to a Data flow diagram
- adds a Data Flow to a Data flow diagram

Reports

- opens the Generate HTML report dialog


- opens the Generate Rich Text Format (RTF) report dialog

Align

- lines up the bottom edges of the selected items


- lines up the left edges of the selected items
- lines up the right edges of the selected items
- lines up the top edges of the selected items

CASE Studio 2 – manual http://www.casestudio.com 7/98


CHARONWARE
database design/modeling tools

Model type

- displays the Entity Relationship Diagram


- displays the Data Flow Diagram

Submodels
- opens the Submodels dialog
- opens the Text objects dialog (Triggers, Procedures...)
- opens the Compare Versions dialog (Model comparison)
- opens the User Roles dialog
- opens the Users dialog
- opens the To-Do list dialog
- opens the Templates Editor dialog

Edit

- allows you to insert items into the Clipboard (CTRL+C)


- cuts selected items (CTRL+X) and places it on the internal clipboard
- pasts selected items (CTRL+V) from the internal clipboard

Colors and fonts

- opens the left sided Overview Tree


- opens the Font dialog
- opens the Color bar (allows you to change the backgound color)
- re-arranges ERD or DFD objects automatically (autolayout) NEW !

CASE Studio 2 – manual http://www.casestudio.com 8/98


CHARONWARE
database design/modeling tools

Exit

- closes CASE Studio 2


- opens the Help file

Hotkeys
Ctrl + N : Creates a new model
Ctrl + O : Opens a model
Ctrl + S : Saves your current model
Ctrl + W : Closes the current model
Ctrl + P : Prints the current model

F5 : Redraws the desktop


F6 : Autolayout NEW !

Ctrl + F9 : Opens the Model Check window


F9 : Opens the Script Generation window

Ctrl + E : Opens the Model Explorer


Ctrl + L : Opens the Templates Editor window
Ctrl + T : Opens the Text Objects window
Ctrl + Alt + T : Opens the To-Do List window
Ctrl + U : Opens the Dictionary (User Types)
F11 : Opens the Gallery window

X: Pointer
E: Entity
R: Identifying relationship
O: Non-identifying relationship
M: Relationship M:N
I: Informative relationship
S: Stamp
N: Note

CASE Studio 2 – manual http://www.casestudio.com 9/98


CHARONWARE
database design/modeling tools

Display modes
CASE Studio 2 works with the physical model only, however, you can view the model in two
modes. The first mode is a Physical View, the second mode is a Logical View.

When creating an ERD the program allows you to define logical names (Entities, Attributes)
as well as physical names (Tables, Columns). Since logical names may include spaces and
special characters and physical names shouldn't, CASE Studio 2 replaces spaces and special
characters with underline marks automatically. You can also add other logical information to
the model, as Notes, Stamp, Text descriptions etc .

You can enable or disable the physical view by clicking on the icon or by selecting the
“Physical view“ item from the „View“ menu.

Logical view Physical view

Display levels

Entities can be displayed in four different display levels:

• entities (only entities are displayed)


• primary keys (diagram shows only entities and its primary keys)
• keys (all keys are visible)
• all (all attributes are visible)

Indexes can be displayed at the bottom of each entity regardless of the active display level.
To display indexes, click the icon or select the „Display indexes“ from the „View“ menu.

CASE Studio 2 – manual http://www.casestudio.com 10/98


CHARONWARE
database design/modeling tools

Creating basic Entity relationship diagrams

Selecting the target database


CASE Studio 2 supports more than twenty database systems. Because CASE Studio 2
supports so many database specifics, it is necessary to select a Target database first. Click
the „New model“ icon or select the „New Model“ item from the „File“ menu. A new dialog
opens. Select the desired database system for which you would like to create a model, and
press OK. A new empty model will be created. The Status bar will now display the name of
the selected database.

Note: CASE Studio 2 allows you to create support for currently unsupported databases. In
other words it is programmable and configurable.

Creating new entities


Click on the Entity icon from the ERD objects toolbar and move your mouse cursor over
the Desktop area. Clicking anywhere over the desktop area will add a new entity to the
diagram. Double click the entity (or right click on the entity and select the „Edit Entity“
item) to open the Entity dialog. Define the Entity name (logical name) first.

CASE Studio 2 – manual http://www.casestudio.com 11/98


CHARONWARE
database design/modeling tools

The software synchronizes the Entity name (logical name) and the Table name (physical
name). The physical name will be synchronized only if the Entity and Table names are
indentical (empty, for example) or if the names are in accordance with the defined
synchronization rules. In both cases, non-standard characters and spaces are replaced with
underline marks automatically.

Of course, it is possible to change the rules of synchronization. For example, if you require
the system to name the table as „P_EntityName“, you can set up the rules accordingly. To
re-define the synchrnonization rules, right click the desktop area and select Model
Properties (or press the Model Properties icon). Click tab Settings and re-define the rules
for Table Name Synchrnonization. The conditions will have to be specified as:

„P“+%entname%

Tip: When you click on the entity, press and hold a "Shift" key at the same time. The button
surface turns blue and you can add as many entities to the model as you desire. This rule
applies also to all other objects. To turn off this feature, click on the arrow symbol on the
entity toolbar. The entity or relationship symbol will then turn off the highlighting.

CASE Studio 2 – manual http://www.casestudio.com 12/98


CHARONWARE
database design/modeling tools

Adding new Attributes


New attributes can be added to any entity by one of two methods - Standard and Fast. We
will start with the standard method. Double click the entity to open the Entity dialog and
click tab Attributes. Click the large ADD button.

Define both, Attribute and


Column names. As you see, the
synchronization works here as
well. On the top, you can see
three checkboxes.

• Key
• Not null
• Unique

Check the Key checkbox to


define the attribute as the
Primary key. Check the Not
Null checkbox to define the
attribute as Not Null (must
have a value) and check the
Unique checkbox to define the
attribute as Unique item.

Select an appropriate data type


from the Data type drop down
menu. (If you select for
example Decimal datatype, you
will be allowed to specify the
Length and Decimal values.)
When you are done, define the
Default and Check values and
Default, Check and Unique
constraint names Options are
accessible only if the items are
supported by the target
database.

Example: attribute Rating may have the Default value specified as „3“ and the Check
constraint may be defined as „%value% > 0“. (When generating the SQL script the macro
%value% will be replaced with the attribute name. In this case „rating“.) Of course, you will
likely be interested in the advanced specification of the Attribute. For setting advanced
options, please see the Advanced Tab. The Advanced tab will be explained later.

The second method of adding new attributes is faster. Edit your entity and click the
Attributes tab. Write the Attribute name into the input field at the bottom and then click the
small ADD button.

CASE Studio 2 – manual http://www.casestudio.com 13/98


CHARONWARE
database design/modeling tools

Of course, this method is not as complex as the first one, however, it might save you a
significant amount of work if you have a large number of entities to create.

CASE Studio 2 uses a Default data type for all new attributes. You may easily change the
default type as follows: Right click the desktop and select the Model properties item (or
click the Model properties icon). Click the Settings tab and redefine the Default data type.
Press OK to confirm your changes.

Tip: Any attribute can


be easily moved or
copied from one entity
to another. Place your
mouse cursor over the
attribute you wish to
move/copy. Press a
CTRL key + click the
attribute and hold
down. Move your
mouse over the entity
where the attribute
should be moved or
copied and release the
left mouse button.
(Use CTRL key to
move the attribute,
CTRL+SHIFT to copy
the attribute.)

Example of generated SQL – Entity „Customer Rating“ (Firebird)

Create Table T_CUSTOMER_RATING (


title Char(40) NOT NULL,
director Char(40) NOT NULL,
rating Smallint Default 3 Constraint check_rating
Check (rating > 0),
Constraint pk_T_CUSTOMER_RATING Primary Key (title,director)
);

CASE Studio 2 – manual http://www.casestudio.com 14/98


CHARONWARE
database design/modeling tools

Creating relationships between entities


Click the Identifying
relationship icon and move
your mouse cursor over
any entity (Parent entity),
press and hold the left
mouse button, continue to
hold down the button, and
move your mouse cursor
over another entity (Child
entity). Release the left
mouse button to create a
relationship. Double click
the relationship line to edit
the Relationship.

Specify the Name of the


relationship, select the
linking method (primary
key, unique item, or
alternate key) and choose
the Relationship type.. You
can choose from:

• Identifying
• Non-identifying
• Informative

Identifying relationship - The Primary key migrates from the parent entity to the child
entity and there becomes a part of the primary key. It is used when the primary key of the
child entity is unable to provide definite identification. An entity, connected with a parent
entity through an identifying relationship, is called a "dependent" entity and is displayed in
the model with rounded corners.

CASE Studio 2 – manual http://www.casestudio.com 15/98


CHARONWARE
database design/modeling tools

Non-identifying relationship - The Primary key migrates from the parent entity to the
child entity and does not become a part of the primary key. Non-identifying relationship are
represented by dashed lines. In the dependent table the attribute is referred to as a foreign
key.

Informative relationship – it is used only as logical information. Informative relationships


have no significance for the generation of SQL scripts.

Other specific types of relationships are M:N relationships and Self-relationships

M:N relationship – for example many suppliers may have many articles and any article may
have multiple suppliers. M:N relationships can be created in the same manner as standard
Identifying or non-identifying relationships, the only difference is, that you have to choose
the M:N relationship icon. When an M:N relationship is established, CASE Studio 2 creates a
third table automatically -- as it is required by the database and as it corresponds to
Database modeling theory.

Self-relationship – a person from table Person may be married to another person from
the same table for example. In our example, we track movies with more episodes.

Generated SQL – Entity “T_FILM” (Firebird)

Create Table T_FILM (


film_id Integer NOT NULL,
title Char(40) NOT NULL,
director Char(40) NOT NULL,
production_company Char(40),
genre_id Integer NOT NULL,
min_age Integer,
film_ID_episodes Integer,
Primary Key (film_id)
);

Alter Table T_FILM add Constraint


ak_title_director UNIQUE
(title,director);
To create a self-relationship, right click
an entity and select Self-relationship. Alter Table T_FILM add Foreign Key
(film_ID_episodes) references T_FILM
(film_id) on update no action on delete
no action ;

Note: When creating relationships, CASE Studio 2 adds a new attribute to the Child entity.
Such behavior is logical, because a foreign key cannot exist without a relationship.

CASE Studio 2 – manual http://www.casestudio.com 16/98


CHARONWARE
database design/modeling tools

Using the Rolename feature


No database system allows you to name two columns of the same table with identical
names. If you create a new self-relationship, CASE Studio 2 adds a new attribute to the
same entity and both the primary key and foreign key have identical Attribute names as well
as Column names. If you try to verify the model, you will receive error messages. To avoid a
multiple instances of the same column name, it is necessary to use the Rolename feature.

Edit the Foreign key, change the Column name (physical name) and specify a new Rolename.
The attribute name (logical name) cannot be changed as renaming both names (Attribute
and Column names) will result in chaos.

Notes:

• Multiple attributes can have


the same Attribute name

• Multiple attributes cannot


have the same Column name

The Rolename feature


should be used in the
following cases:

• whenever you want to


change a Foreign key
attribute name

• whenever you create a


Self-relationship in CASE
Studio 2

CASE Studio 2 – manual http://www.casestudio.com 17/98


CHARONWARE
database design/modeling tools

Connecting Parent and Child entities


CASE Studio 2 allows you to connect Parent and Child entities through the following unique
values:

• Primary key
• Unique item
• Alternate key (or Unique
index – for example in
PostgreSQL models)

To change the linking


method double click the
relationship line and click the
Type tab. Choose the right
method from the Linking
method drop down menu. If
no Unique item or no
Alternate key exists, the
drop down menu includes
only the Primary key item.

Note: Some databases don't


support alternate keys.

Example of generated SQL (Firebird)


Create Table T_FILM (
film_id Integer NOT NULL,
title Char(40) NOT NULL,
director Char(40) NOT NULL,
production_company Char(40),
genre_id Integer NOT NULL,
min_age Integer,
film_ID_of_series Integer,
Constraint pk_T_FILM Primary Key (film_id)
);

Alter Table T_FILM add Constraint ak_title_director


UNIQUE (title,director);

Create Table T_CUSTOMER_RATING (


title Char(40) NOT NULL,
director Char(40) NOT NULL,
rating Smallint Default 3 Constraint check_rating
Check (rating > 0),
Constraint pk_T_CUSTOMER_RATING Primary Key (title,director)
);

Alter Table T_CUSTOMER_RATING add Constraint is_rated Foreign Key


(title,director) references T_FILM (title,director) on update no
action on delete no action ;

CASE Studio 2 – manual http://www.casestudio.com 18/98


CHARONWARE
database design/modeling tools

For some databases (e.g. PostgreSQL) CASE Studio 2 generates Unique indexes instead of
Alternate keys.

Example of generated SQL (PostgreSQL)


Create table T_FILM
(
film_id Integer NOT NULL,
title Char(40) NOT NULL,
director Char(40) NOT NULL,
production_company Char(40),
genre_id Integer NOT NULL,
min_age Integer,
film_ID_of_series Integer,
constraint pk_T_FILM primary key (film_id)
);

Create unique index ak_title_director on T_FILM (title,director);

Create table T_CUSTOMER_RATING


(
title Char(40) NOT NULL,
director Char(40) NOT NULL,
rating Smallint Default 3 Constraint check_rating Check (rating > 0),
constraint pk_T_CUSTOMER_RATING primary key (title,director)
);

Alter table T_CUSTOMER_RATING add Constraint is_rated foreign key


(title,director) references T_FILM (title,director) on update
restrict on delete restrict;

CASE Studio 2 – manual http://www.casestudio.com 19/98


CHARONWARE
database design/modeling tools

Displaying Partiality
When editing relationship settings, partiality for Parent and Child tables can be defined. It
might be useful for producing a better view of the database structure. Moreover, partiality
can be synchronized with cardinality and Not Null settings.

Click the Type tab and set Mandatory or Optional values as necessary. The relationship
lines will change accordingly.

Parent: Mandatory
Child: Mandatory
A teacher MUST have a
lecture (a record related to a
lecture is mandatory),
a lecture MUST be attached
to a teacher (a record related to a teacher is also mandatory. Teacher is Mandatory).

Parent: Mandatory
Child: Optional
A teacher MAY have a lecture
(a record related to a lecture
is Optional, that's why the
Lecture is Optional), a lecture MUST be attached to a teacher (Teacher is Mandatory).

Parent: Optional
Child: Mandatory
A teacher MUST have a
lecture (Lecture is
Mandatory), a lecture MAY be
attached to a teacher (Teacher is Optional).

Parent: Optional
Child: Optional
A teacher MAY have a lecture
(Lecture is Optional), a
lecture MAY be attached to a
teacher (Teacher is Optional).

NB: The partiality has almost no significance for the final SQL script generating, only the
Not Null settings affects the generated SQL (This will be explained later.).

Note: In the above example, American and Canadian readers would likely be more familiar
with the term “course” or “class” as opposed to a “lecture”.

CASE Studio 2 – manual http://www.casestudio.com 20/98


CHARONWARE
database design/modeling tools

Defining Cardinality
If you need to set up a relationship as 1:5, for example, define the cardinality at the bottom
of the Edit Relationship dialog. An appropriate number will be displayed near the end point
of the selected relationship line.

Note: this feature is available only for target databases which support triggers. See some of
the currently supported databases:

• PostgreSQL 7.4
• PostgreSQL 7
• Interbase 7
• Interbase 6 SQL 3
• Interbase 6 SQL 1
• Firebird 1.5
• MS SQL 2000
• DB2 UDB v.8.1
• DB2 UDB v.7
• Oracle
• Sybase ASE 12.5 and others

In CASE Studio 2, you can generate referential integrity declaratively or via triggers. If you
want to generate cardinality, you must generate the referential integrity rules via triggers,
not declaratively.

Example of generated SQL – cardinality in a trigger (Firebird)

/* Maximum cardinality of T_BORROWING cannot be exceeded */

if (new.customer_id is not null) then


begin
select count(*)
from T_BORROWING
where new.customer_id = T_BORROWING.customer_id and
new.customer_id <> old.customer_id
into :maxcard;
if (maxcard >= 5) then exception except_upd_ch_card;
end

CASE Studio 2 – manual http://www.casestudio.com 21/98


CHARONWARE
database design/modeling tools

Setting up Referential integrity rules


Lets say we have a model
with some entities and a
few relationships. We
know how to display the
Cardinality, Partiality etc.
The next very important
step we have to do is
setting up the referential
integrity rules for Parent
and Child entities. Right
click the relationship line
(or double click the line)
and select the Edit
relationship item. The
Relationship dialog opens.

Click on the Referential


integrity tab and set the
required rules from
appropriate drop-down
menus. You can change the
NONE rule to:

• Restrict (default)
• Cascade
• Set NULL
• Set Default

The default rule can be re-


configured.

The referential integrity can be generated declaratively or via triggers. CASE Studio 2
generates the referential integrity based on the selected method and based on the
capabilities of the target database.

Note: Some databases don't support all Referential Integrity (RI) rules.

Example of generated SQL – referential integrity (Firebird) – No action

Alter Table T_BORROWING add Constraint makes Foreign Key


(customer_id) references T_CUSTOMER (customer_id) on
update no action on delete no action ;

CASE Studio 2 – manual http://www.casestudio.com 22/98


CHARONWARE
database design/modeling tools

Understanding Foreign keys


If you create a new Identifying relationship, CASE Studio 2 adds a copy of the Primary key
from the Parent table to the child table as a Primary Foreign key - PFK (because the foreign
key is a part of the primary key in child table).

If you create a new Non-Identifying relationship, CASE Studio 2 adds a copy of the Primary
key to the child table as a Foreign key - FK (the foreign key is not a part of the primary key
in the Child table).

Primary keys are always defined as Not Null, but foreign keys don't necessarily have to be
defined as Not Null items. That is why you can take advantage of the implemented Not null
synchronization. Right click the desktop area and select the Model Properties item. Click tab
Settings and check/uncheck the „Synchrnonize Not Null with partiality“ checkbox. If you
create a new non-identifying relationship, the Primary key maintains the Non Null
specification, however, the Foreign key's Not Null specification will be dependent upon the
Partiality (Mandatory -> FK = Not Null)

CASE Studio 2 – manual http://www.casestudio.com 23/98


CHARONWARE
database design/modeling tools

Foreign keys mapping (how to create a compound foreign key)


Occasionally, you might need to create a compound foreign key (combine two primary keys
of two different tables together and create only one foreign key in the same child table), or
change the foreign key to primary key etc. Such techniques are not absolutely clear as to
their implementation methods, however, CASE Studio 2 offers you a method for managing
this task.

If you reverse engineer a database without relationships, a new model will be created,
however, information about foreign keys will be lost (foreign keys cannot exist without
relationships). If you then create a new relationship, a new foreign key will be added to the
child entity automatically and the child entity will therefore include two attributes of the
same name (the original attribute and the newly added foreign key). You are not required
however, to erase the original attributeand then create the new relationship. You can
instead, remap the foreign key. Right click the relationship line and select the Foreign key
item. Click on the name which belongs to the New FK column and change the Foreign key
to any other item. In this case choose the attribute of the same name.

CASE Studio 2 – manual http://www.casestudio.com 24/98


CHARONWARE
database design/modeling tools

Imported foreign keys


In CASE Studio 2, all foreign
keys created by the standard
method (connecting two
entities by a relationship) are
“imported” - it means imported
from parent entities. On the
other side, non-imported fo-
reign keys can be created via
the Foreign keys mapping
function, for example.

Imported foreign keys are


automatically deleted when the
primary key is erased or when a
relationship is deleted.

If you need to delete the pri-


mary key and maintain the
foreign key, please uncheck the
check box “Imported” at the
bottom of the dialog.

If you uncheck this check box


and delete the primary key
from the parent table, your
foreign key in child table will still
exist in the model.

Please make sure that changing


the “imported” value is really
necessary, because this situation
should occur only rarely.

CASE Studio 2 – manual http://www.casestudio.com 25/98


CHARONWARE
database design/modeling tools

Specifying relationship properties


We have gone through almost every relationship specification. Now we know how to create
simple entity relationship diagrams in CASE Studio 2. Before we start with more
complicated matters, it would be fine to make a brief summary of all relationship settings.
Here it is:

• tab Type – a place where you can name the relationship, select Linking method,
relationship type, define partiality and cardinality

• tab Referential Integrity – a place where you set up the referential rules for the
relationship

• tab Advanced – a place where you can define other database specifics. For example for
Oracle models, you can enable/disable the „Referential integrity Deferrable“ option. (It is
also a place where your own User-Defined Variables can be added, but it will be
explained later)

• tab Keys – you can see any keys which have been created previously, whether
automatically or manually. If you use the foreign keys mapping feature, for example, you
will find there a detailed description of the foreign key.

• tab Description – text inserted into the Description is used as a Hint (Insert any text
into the Description text area and confirm changes. Then move your cursor over the
relatinoship line. The text should appear.)

• tab Notes – text inserted


into the Notes will not be
used for generating SQL.
It is only logical
information, however,
useful to you.

• Check box Generate –


uncheck this check box
to instruct CASE Studio 2
to not use the rela-
tionship for the final SQL
script generation.

Note: A relationship will


not be generated if the
Parent entity is not
generated, regardless of
the Generate check box
settings.

CASE Studio 2 – manual http://www.casestudio.com 26/98


CHARONWARE
database design/modeling tools

Advanced database design

Defining Advanced options – Entity


Before we start with creating indexes, alternate keys, triggers, stored procedures and other
advanced parts of database design, it would be useful to go through all possible entity and
attribute settings. Here, you can learn where and how to define storage parameters, how to
create multiple column check constraints etc.

• tab Properties – a place where entity properties can be specified. For example, you can
define a Primary key constraint name on this tab.
• tab Advanced – on this tab you can access and define other database specifics. Options
are database dependent. For example, for Oracle models, you can specify Owners,
Tablespaces for tables, and Tablespaces for Primary keys etc. For Firebird models you
can define External file, Explicitly named Indexes for PK constraints and so on.
• tab Indexes – a place where you can add and manage Indexes. We will discuss creating
indexes later.
• tab Alternate keys – a place where you can add and manage Alternate keys. Alternate
keys will be discussed later.
• tab Others – some situations cannot be modelled perfectly. Lets say we need to add a
multiple column check to our model.. This can be done easily in CS2. Write the SQL
code for the check in the Others Tab. For Example:

Alter table T_HOTEL add constraint CHECK_AGE_TO


check (AGE_TO between AGE_FROM and 17);

• tab Relationship – a place where you can see statistical data regarding dependent
relationships
• tab Storage – some databases, like for example Oracle, allow you to define where the
data will be physically saved. This tab is a where the storage specification information will
be written
• tab Descriptions – a place where you can write descriptions. The content will be used
for the final SQL script generating (the text will be generated as a Comment in table) and
also as a hint (move your mouse cursor over the entity to see the hint). This description
can be very useful when viewing the model as the information will be readable regardless
of the model display magnification.
• tab Notes – a place where you can write Notes
• checkbox Generate - check this checkbox to instruct CASE Studio 2 to use the entity
for the final SQL script generating. If you uncheck the checkbox, the entity will not be
generated.

CASE Studio 2 – manual http://www.casestudio.com 27/98


CHARONWARE
database design/modeling tools

Defining Advanced options – Attribute


As an example of Advanced Attribute options, consider that in MySQL, you can specify any
attribute as Autoincrement, Unsigned, Binary etc. To define these options, use the
following:

• tab Attribute – a place where the standard settings, (attribute and column names
definition, data type selection, check constraints definition etc.) can be specified

• tab 2 – a place where special information about attributes can be stored. The tab
includes three input fields: Def, Def2 and User type. Whatever you write into the Def
field will be generated immediately after the data type specification, whatever you write
into the Def2 field will be generated at the end of the attribute definition. Example: for
InterBase models, you can define Character set and Collation. Try to create the following
attribute and remember to write appropriate values into the Def and Def2 fields.

Attribute name = First Name


Column name = first_name
Type = char(20)
Def = CHARACTER SET WIN1250
Def 2 = COLLATE WIN1250

If you perform SQL script generation, the attribute will be generated this way (Firebird) :

first_name char(20) CHARACTER SET WIN1250 NOT NULL


COLLATE WIN1250

Note: The use of the third field „User type“ will be explained later.

• tab Advanced – a place where additional settings can be specified. These options are
database dependent. For example for MySQL models, you can specify the
Autoincrement, Unsigned, Zerofill and other settings. For Sybase ASE models, you can
specify Default Object, Rule Object, Identity, for Firebird model, you can define Array
declaration, Explicitly named Index for Unique constraint and so on.

• tab Description – a place where descriptions can be written. Descriptions will be used
for the final SQL script generating (some databases don't support Comments on
Columns)

• tab Notes – a place where notes can be written. Notes have no significance for the SQL
script generation, but can be added to HTML or RTF reports.

CASE Studio 2 – manual http://www.casestudio.com 28/98


CHARONWARE
database design/modeling tools

Using the ”Empty” data type


CASE Studio 2 allows you to create computed columns using the Empty data type. Edit any
attribute and from the Data type drop down menu select Empty. Then specify the Def and
Def2 values on tab 2. See the following example:

• Attribute name: total price with VAT


• Column name: total_price_VAT
• Datatype: Empty
• Def (tab 2): computed by (total_price * ((VAT+100)/100))

Example of generated SQL script (Firebird)

total_price_VAT computed by (total_price * ((VAT+100)/100))

Using the Dictionary


A very useful part of CASE Studio 2 is the internal Dictionary. In the Dictionary, User
defined data types (for example data type „Square“) and other data types specifications can
be stored. The following diagram shows you all possible dictionary items:

Dictionary

Standard Dictionary Items User Defined Data Types

• Standard data types which will be • User Defined Data types (unsupported
generated by CASE Studio 2 as by target database system).
• Domains or Example: Square (length, width)
• Standard data types • Special Data Types
Example: Price (Decimal 10,2) Example: Data types NAMED ROW,
DISTINCT, OPAQUE (Informix) and
other special data types.

CASE Studio 2 – manual http://www.casestudio.com 29/98


CHARONWARE
database design/modeling tools

Creating and using Standard Dictionary Items


You can add new items to the dictionary and use them repeatedly in your model by
specifying a reference to appropriate dictionary item. During SQL Script Generation you will
be allowed to choose, whether the dictionary items will be generated as domains, or as
standard data types.

Creating new dictionary items

Select the User types item


from the Dictionary menu or
press CTRL+U. A new dialog
opens.

Click the Add button. Specify


the Name (e.g. Price),
Physical name, select
appropriate data type - for
example Float and define the
Check, Default (e.g. 100), Def
and Def2 values. Click tab
Advanced to specify other
settings, click OK to confirm
changes and close the
Dictionary.

Using the dictionary items

Edit any attribute and select


the data type. The new
„Price“ option is now
accessible. You can see a blue
dictionary icon before the
data type name as a
notification that it's a user
defined data type. If you
select the Price data type,
CASE Studio 2 also displays
appropriate Default and
Check values. In our case, you
can see the value 100.

CASE Studio 2 – manual http://www.casestudio.com 30/98


CHARONWARE
database design/modeling tools

To define the Default and Check


values, check the checkbox on
the right side. The input fields
change to accessible mode, and
re-define the value (in our
example to 80 – see the
following screen shot).

The same method can be used


for changing the Check value.

The internal Dictionary can be


accessed directly from the
Attribute dialog. At top right
corner, there is a blue dictionary
icon. If you click the icon, the
Dictionary dialog opens.

Later, during SQL Script


Generation, you can decide
wheter dictionary items should
be generated as domains or not.

Here are the two possible


outputs:

Example (Firebird) -
Dictionary items generated as domains

Create Domain "PRICE" As Float;


Create Table "T_BORROWING" (
"exemplar_id" Integer NOT NULL,
"total_price" "PRICE" Default 80,
Primary Key ("exemplar_id")
);

Example (Firebird) - Dictionary items generated as standard data types

Create Table "T_BORROWING" (


"exemplar_id" Integer NOT NULL,
"total_price" Float Default 80,
Primary Key ("exemplar_id")
);

CASE Studio 2 – manual http://www.casestudio.com 31/98


CHARONWARE
database design/modeling tools

Creating and using User Defined Data Types


In CASE Studio 2, you can also create your own data types. For example data type Square,
Circle etc or special data types.

All user defined data types:

• may be linked with Text Objects items (Text objects will be explained later, in chapters
„Permanent Text Objects“ and „Database Dependent Text Objects“.
• may be stored in the Dictionary (see the previous section)
• use the Empty data type specification

Example: Lets say we would like to use the Distinct data type in a model for Informix. The
output should be:

CREATE DICTINCT TYPE dist_type1 AS integer;

Create Table Exemplar (


ID Integer NOT NULL,
Price dist_type1,
Primary Key (ID)
);

Step A) We will create a new Text Object item. Press CTRL+T to open the Text Objects
dialog. Right click the Distinct types item and select Add. Name the item and write the
definition into the Content tab.

(note: all triggers, stored procedures, views etc. are stored among Text objects)

CASE Studio 2 – manual http://www.casestudio.com 32/98


CHARONWARE
database design/modeling tools

Step B) We will create new Dictionary item (new User Defined Data Type) -- for example
MyDistType. The „Empty“ data type must be selected from the Datatype drop down
menu and to the User type field the name of previously defined dist_type1 text
object must be written (a reference to the text object must exist – see the screen shot
below).

CASE Studio 2 – manual http://www.casestudio.com 33/98


CHARONWARE
database design/modeling tools

Step C) We will assing the new dictionary item to attributes.

Add a new attribute to any entity and select the MyDistType data type from the Datatype
drop down menu.

In this way, you can create your own data types for any database, or, for example Named
Row Types, Opaque Types and Distinct types for Informix models.

CASE Studio 2 – manual http://www.casestudio.com 34/98


CHARONWARE
database design/modeling tools

Creating indexes
In CASE Studio 2, you can create Indexes on tab Indexes of the Entity dialog. To edit any
already existing entity (with attributes), make the Indexes tab active and Click Add.

Define the Index name first. In the middle of the dialog box, you can see two small lists. The
left side list includes a list of available attributes, the right field includes a list of data fields
currently in the index. Between the two lists there is a panel with two arrows, < and >.
Select an attribute from the left list and click the > button to add the attribute (data field) to
the index. You can add multiple attributes (data fields) in any order to the index as well as
choosing whether the fields should be sorted in ascending or descending order. (If you wish
to remove an attribute from the index, highlight it, then click the < symbol to remove it
from the index list.) To change the order of items in the list, highlight the item you wish to
move, then use the up or down arrows to position the attribute appropriately in the list. To
change the order from Ascending to Descending, click the value in column A/D (this option
is not available for all target databases as such settings are database dependent). You can
also specify other index settings. Explore the tabs to see other options.

CASE Studio 2 – manual http://www.casestudio.com 35/98


CHARONWARE
database design/modeling tools

Creating alternate keys


As you already know, parent and child entities can be linked through Alternate keys.
Alternate keys are used when you want to link the two entities using two attributes
considering the two attributes makes one unique item. To create a new alternate key, edit
an entity (with attributes) and click the Alternate keys tab. Click ADD to create a new
alternate key.

Define both, Name and Physical name values. Select an attribute from the left list and use
the > button to add the attribute to the right list. As an exercise, try to create a new
alternate key of two or more attributes, then, go through all other tabs to see which
options are accessible and click OK to confirm changes. Then edit a relationship which
belongs to the entity and try to change the linking method from Primary Key to Alternate
Key.

For further information on creating keys, see the previous section.

CASE Studio 2 – manual http://www.casestudio.com 36/98


CHARONWARE
database design/modeling tools

Working with Triggers, Views, Stored procedures...


CASE Studio 2 supports Triggers, Views, Stored procedures, Functions, Sequences, Types,
Type bodies, Packages, Synonyms etc. All those elements of your database design are
supported as text objects. This means that CASE Studio 2 doesn't display them in the
diagram visually and doesn't parse them. However, you can create, for example, stored
procedures and of course, the stored procedures will be inserted into the generated SQL
script. Moreover, you can create patterns for Views, Triggers and Stored procedures.

You will find that almost all of the elements we have implemented in this fashion are
database dependent.

As an example, not every database supports External Functions -- which we have


implemented as a text object.

CASE Studio 2 – manual http://www.casestudio.com 37/98


CHARONWARE
database design/modeling tools

Permanent Text objects


The only permanent Text objects are:

• Others – includes the content of the Others tab of the Entity dialog (e.g.
Multiple column checks)
• User Triggers – a place where you can assign custom triggers to entities. Note:
Standard triggers for referential integrity are not accessible here as CASE Studio
2 generates all RI triggers automatically!
• Procedures – a place where custom stored procedures can be created
• Views – a place where views can be created
• Before – whatever you write in this section will be generated at the beginning of
the SQL script. It is an ideal place to add connection strings if your database
needs them.
• After – whatever SQL code you write to this section will be generated at the
very end of the SQL script.

Database dependent Text objects


Other database elements are database dependent. The list below includes only few of them:

• Functions
• Packages, Package bodies
• Types, Type bodies
• Sequences
• Synonyms
• Object tables
• Default objects
• Rule objects etc.

Creating Text objects


Defining triggers, views and other parts of your model.

• Click the Model menu and select the Text objects item (or press CTRL + T)
• Right click the Views folder and select Add
• Specify the name and click OK
• Write your view into the Content tab
• When you are done click the OK icon (green icon) to confirm changes

If you create numerous Views or Triggers etc., you might feel the need to sort or group
them. Use the two red arrows to move your Views into the desired position. The same
method can be used for sorting almost all text objects.

CASE Studio 2 – manual http://www.casestudio.com 38/98


CHARONWARE
database design/modeling tools

Creating patterns for Text objects


The ability to create patterns for views, stored procedures and triggers is very useful for all
those who regularly define text objects. Open the Text objects dialog and select the
Patterns item from the Settings menuwhich opens the Patterns dialog. Click the View
Pattern tab.

The SQL program code that you insert into the text area will be used for every new View.

This feature saves you considerable effort and avoids errors as you now have a template. As
you can see, it is also possible to use some of the internal Macros.

The list of accessible macro values is as follows:

%tmplNow% - time stamp


%tmplDate% - date
%tmplTime% - time
%tmplTriggerName% - trigger name
%tmplTableName% - table name (for triggers only)
%tmplProcedureName% - stored procedure name
%tmplViewName% - view name

You can also access these patterns via the File menu (Choose the Extended Settings and
Patterns item).

CASE Studio 2 – manual http://www.casestudio.com 39/98


CHARONWARE
database design/modeling tools

Creating user roles and specifying user permissions


In CASE Studio 2 models, you can specify Users and assign roles to the Users. To add a role,
click the User roles from the Model menu. The User roles dialog opens. Click add to create
a new user role. Define the Name and Physical name on tab Role, then click tab Permission
and specify permitted actions (Select, Insert, Update, Delete etc.).

When you are done, click the Users tab. Because no User exists in the model, the area is
currently empty. After you create several users, all of them will be listed in the area and you
will be allowed to assign users to roles.
To add new users to the model, Click the Model menu and select Users.
Click the Add button and specify both, User and Physical name values. Then click the
Permissions Tab and define appropriate permissions for actions (again, Select, Insert,
Update, Delete etc.). On the User Roles tab, you can assign the User to a previously
defined role.

Of course, user roles and permissions are not supported by all databases since it is not
possible to manage such items via SQL commands in all database systems.

CASE Studio 2 – manual http://www.casestudio.com 40/98


CHARONWARE
database design/modeling tools

Database Rights and Permissions


A permission – in database terminology - is the right to access an object – usually a table.
These permissions can be assigned to Users, and sometimes to User Roles. The creator of
the database has all the rights associated with the database object, and they can transfer
some (or all) of the rights to the users and developers of the database.

A database creator (or owner) can manage these permissions through the following:
Grant Rights to the Database or more usually objects witin the database; and,
Deny Rights of access to objects within the database; and,
Revoke Rights of access to database objects.

Object Permissions Description


Select Allows you to read data from a table or view. Generally permission
can be applied to individual columns and may be applied to User
Defined Functions (UDF).
Insert Allows you to add new data records (rows) to a table or view.
Delete Enables you to remove data rows (records) drom a table.
Update Permits you to change data within a record. It is usually possible to
grant Update rights on columns within the database.
Execute Enables you to execute a stored procedure.
DRI Declarative Referential Integrity. (DRI) rights allow you to change
or add foreign key constraints on a table.

Statement Description
Permissions
Backup DB Allows you to backup the DB, files or filegroups.
Backup Log Allows you to copy the transaction log.
Create DB Enables you to generate a new databse object.
Create Default Permits you to create a default object.
Create Function Enables you to create a UDF.
Create Procedure Enables you to create Store Procedures.
Create Rule Enables you to create a rule.
Create Table Enables you to create a table object.
Create View Enables you to create a View Object.

Statements are usually of the form:

GRANT SELECT ON CITIES TO VACLAV

Although the rights shown above are “normally” the way things are done, many databases
adopt their own terminlogy and implementations.

CASE Studio 2 – manual http://www.casestudio.com 41/98


CHARONWARE
database design/modeling tools

Using the Model verification feature

Verifying models
CASE Studio 2 allows you to verify your models. The verification returns Errors, Warnings
and Hints. You can verify your ERD globally (for multiple appearances of relationships,
entities etc.) as well, you can verify your model with regard to the selected target database.
For example: for Oracle models you can run a verification of duplicate constraint definitions
and for MySQL models you can execute a verification for the presence of 'Number of
indexed characters for primary key' in innoDB tables etc.)

Accessing verification
You can verify your model at any time by pressing the CTRL+F9 keys or you can verify the
model before you execute the SQL script generation (you will have to check the
appropriate checkbox on the SQL script generating dialog).

CASE Studio 2 – manual http://www.casestudio.com 42/98


CHARONWARE
database design/modeling tools

Using submodels

Creating submodels
A Submodel –is a feature which will help you
to organize your work. You can select
multiple entities and add them to a new
submodel. Later, you will be allowed to
generate SQL script only for a selected
submodel or to generate an HTML or an
RTF report of the submodel.

There are two ways to create a submodel: a)


Select the Submodel item from the Model
menu. A new dialog opens. Click Add and
define the Submodel name. Then click the
Entities tab and select entities you wish to
assign to the submodel. Click the Grid Tab to
set the grid settings. When you are done,
click the Advanced tab and specify the
submodel's display settings. Click OK to
confirm changes.

b) Select multiple entities in the main model


(use the Shift key to make multiple items
selection) and right click on any of them. A
new dialog opens. Click the New Submodel
item, define the Submodel name and define
settings on the Entities Tab, the Grid tab and
the Advanced tab. Click OK to confirm the
creation of the submodel.

A Few facts about submodels:

• An entity can be assigned to numerous submodels

• An entity can be easily removed from any submodel (removing entities from submodels
and erasing entities from a model are different actions !)

• An entity created in a submodel is automatically added to the main model

• An entity erased from the submodel is automatically erased from the main model and all
other submodels

• Entity colors and other display settings can be specified for each submodels separately

CASE Studio 2 – manual http://www.casestudio.com 43/98


CHARONWARE
database design/modeling tools

Erasing
submodels
You might need to erase a
submodel. To do that,
please click the Model
menu and select
Submodels. A new dialog
opens. Select the
submodel you wish to
erase and click Delete.
The submodel will be
deleted, however, all
entities will be retained in
the main model.

Removing / Erasing entities


from submodels
You can remove an entity from a submodel
OR erase an entity from a submodel. To
remove an entity, please edit your submodel
(double click on the submodel name or click
the Model menu and select Submodels) and
click the Entities. Tab. Uncheck the
checkbox which belongs to the entity you
wish to remove. If you uncheck the
checkbox, the entity will disappear from the
submodel, however, the main model will still
include the entity. If you want to erase the
entity from a submodel as well as from the
main model, click the entity and press the del
key (or right click the entity and select the
Delete entity).

You will have to confirm the „Are you sure


you want to delete entity EntityName?“
warning to finish this action.

CASE Studio 2 – manual http://www.casestudio.com 44/98


CHARONWARE
database design/modeling tools

Hiding relationship lines


Hiding relationships could be useful when you need to present your work to your client but
do not want to show him/her all the relationships. For example: to hide relationship lines,
right click the desktop area and select the „Visible relationships in Submodel“ item. A new
dialog opens -- „Visible Relationships of submodel“. Enable or disable appropriate
checkboxes to show or hide relationship lines.

CASE Studio 2 – manual http://www.casestudio.com 45/98


CHARONWARE
database design/modeling tools

SQL/DDL script generating

Selecting items
One of CASE Studio 2's key features is the SQL script generation. CASE Studio 2 respects
as many database specifics as possible and that's why you can model almost any possible
situation and generate very detailed and database specific SQL/DDL code. Reading the
following text you will see how powerful the software is.

To open the SQL script generation dialog, select the Generate Script item from the Model
menu or press F9, and the following dialog opens.

Stay on the tab „What to generate“ and define the path and file name where the SQL script
file will be saved. Then check all checkboxes belonging to elements you wish to generate.
For example: Tables, Others, Primary keys, Indexes, Referential integrity, Triggers,
Procedures, Views, Alternate keys, Roles, Insertions before and after scripts etc. Use the A
button to select All items, D button to clear the selection and I button to invert selection.
The selection of check boxes shown above would normally be used to generate a
completely new instance of a database. In other cases you may wish to drop tables before
regenerating them. Of course we assume that you would do any necessary backups
before dropping tables or domains. From the drop down menu at the bottom of the
dialog you can choose whether the script should be generated as Uppercase, Lowerse or if
the system should preserve characters etc. This latter feature may be to your advantage if
your database is case sensitive and you wrote all column names as lowercase and all text

CASE Studio 2 – manual http://www.casestudio.com 46/98


CHARONWARE
database design/modeling tools

objects as uppercase). Enable the Check Script checkbox to run Model verification
automatically. The second checkbox, Default, allows you to store the settings so you will not
have to enter the settings again and again.

Selecting a method
On the „How to generate“ tab,
you can define the method by
which you wish to generate the
SQL script. You can generate
referential integrity for Parent
and Child tables declaratively or
via triggers. -- a database
dependent feature.. You can
generate referential integrity
declara-tively only if it is
supported by the selected
database. Note that some
databases don't support all types
of declarative RI.

On the „How to generate“ tab


you can also enable other
options as for example whether
primary key constraint names
should be generated or not.

Example of generated SQL - Referential itegrity (Trigger)

/* Delete trigger for T_MEDIUM */

Create Trigger td_T_MEDIUM


for T_MEDIUM before delete as
declare variable numrows integer;
begin
/* Restrict child T_EXEMPLAR, when parent T_MEDIUM deleted*/

select count(*)
from T_EXEMPLAR
where T_EXEMPLAR.medium_id = old.medium_id
into :numrows;
if (numrows > 0) then exception except_del_p;

end
^

Example of generated SQL - Referential itegrity (Declarative)

Alter Table T_EXEMPLAR add Constraint is_available_on


Foreign Key (medium_id) references T_MEDIUM (medium_id)
on update no action on delete no action ;

CASE Studio 2 – manual http://www.casestudio.com 47/98


CHARONWARE
database design/modeling tools

Setting Advanced
options
The „Advanced“ tab includes
other database dependent
options. For example for Oracle
models you can enable or disable
the following options: Use
quotation; Generate Owner,
check constraint name, unique
constraint name, not null con-
straint name, comments on
tables and attributes, functions,
synonyms, object tables and so
on. For FireBird models, you can
specify whether the system
should generate functions,
exceptions, generators, blob
filters etc. Define all appropriate
options and click the „Entity list“
tab.

Selecting
submodels
You can generate SQL/DDL
script for any submodel or, of
course, for the main model.
From the Generate drop down
menu select the appropriate
option. By pressing the D and I
buttons you can select all
entities or invert the selection. If
you check the „Only selected
entities“ checkbox, CASE Studio
2 will generate only items where
the Generate checkbox is
enabled (dialogs Entity,
Relationship etc.). Select entities
and click Generate to start the
process. Then click the View
button to see the SQL/DDL
script.

CASE Studio 2 – manual http://www.casestudio.com 48/98


CHARONWARE
database design/modeling tools

You can model your database strucure in few minutes or hours and generate detailed SQL
script automatically. See our example for the more than 300 lines long SQL script based on a
relatively small model. A model which was created in few hours.

Example of generated SQL – model VideoRental.dm2


/*
Created 11.12.2003
Modified 17.3.2004
Project Video rental
Model
Company CHARONWARE
Author Radim Mario Tkacik
Version 1.0
Database Firebird
*/

Create Domain PRICE As Float;

Create Table T_CUSTOMER (


customer_id Integer NOT NULL,
name Char(40),
address Char(50),
Constraint pk_T_CUSTOMER Primary Key (customer_id)
);

Create Table T_GENRE (


genre_id Integer NOT NULL,
name Char(20),
Constraint pk_T_GENRE Primary Key (genre_id)
);

Create Table T_MEDIUM (


medium_id Integer NOT NULL,
medium_type Char(20),
Constraint pk_T_MEDIUM Primary Key (medium_id)
);

Create Table T_EXEMPLAR (


exemplar_id Integer NOT NULL,
film_id Integer NOT NULL,
medium_id Integer NOT NULL,
price_per_one_day Integer,
Constraint pk_T_EXEMPLAR Primary Key (exemplar_id)
);

Create Table T_FILM (


film_id Integer NOT NULL,
title Char(40) NOT NULL,
director Char(40) NOT NULL,
production_company Char(40),
genre_id Integer NOT NULL,
min_age Integer,
film_ID_episodes Integer,
Constraint pk_T_FILM Primary Key (film_id)
);

Create Table T_BORROWING (


exemplar_id Integer NOT NULL,
customer_id Integer NOT NULL,
start_date Date Default 'NOW',
end_date Date,
total_price PRICE,
VAT Float Default 19,
total_price_VAT computed by ( total_price * ((VAT+100)/100) ),
Constraint pk_T_BORROWING Primary Key (exemplar_id)
);

CASE Studio 2 – manual http://www.casestudio.com 49/98


CHARONWARE
database design/modeling tools

Create Table T_ORDER_RECORD (


customer_id Integer NOT NULL,
film_id Integer NOT NULL,
order_date Date,
Constraint pk_T_ORDER_RECORD Primary Key (customer_id,film_id)
);

Create Table T_CUSTOMER_RATING (


title Char(40) NOT NULL,
director Char(40) NOT NULL,
rating Smallint Default 3 Constraint check_rating Check (rating > 0),
Constraint pk_T_CUSTOMER_RATING Primary Key (title,director)
);

Alter Table T_BORROWING add Constraint check_end_after_start Check


((end_date>start_date) or (end_date is null));

Alter Table T_EXEMPLAR add Constraint Alter_Key1 UNIQUE


(exemplar_id,price_per_one_day);

Alter Table T_FILM add Constraint ak_title_director UNIQUE (title,director);

Create Index i_name ON T_CUSTOMER (name);

Alter Table T_BORROWING add Constraint makes Foreign Key (customer_id) references
T_CUSTOMER (customer_id) on update no action on delete no action ;

Alter Table T_ORDER_RECORD add Constraint places Foreign Key (customer_id) references
T_CUSTOMER (customer_id) on update no action on delete no action ;

Alter Table T_FILM add Constraint is_of Foreign Key (genre_id) references T_GENRE
(genre_id) on update no action on delete no action ;

Alter Table T_EXEMPLAR add Constraint is_available_on Foreign Key (medium_id)


references T_MEDIUM (medium_id) on update no action on delete no action ;

Alter Table T_BORROWING add Constraint is_related_to Foreign Key (exemplar_id)


references T_EXEMPLAR (exemplar_id) on update no action on delete no action ;

Alter Table T_EXEMPLAR add Constraint has Foreign Key (film_id) references T_FILM
(film_id) on update no action on delete no action ;

Alter Table T_ORDER_RECORD add Constraint is_required_by Foreign Key (film_id)


references T_FILM (film_id) on update no action on delete no action ;

Alter Table T_FILM add Constraint has_more_episodes Foreign Key (film_ID_episodes)


references T_FILM (film_id) on update no action on delete no action ;

Alter Table T_CUSTOMER_RATING add Constraint is_rated Foreign Key (title,director)


references T_FILM (title,director) on update no action on delete no action ;

CREATE VIEW v_CustomerHasFilm AS


SELECT distinct c.name, c.address, f.title, f.director
FROM T_CUSTOMER c, T_BORROWING b, T_EXEMPLAR e, T_FILM f
WHERE c.customer_id=b.customer_id
and b.exemplar_id=e.exemplar_id
and e.film_id=f.film_id;
set term ^;

CREATE PROCEDURE p_Customer_Has_Num_Film (id integer) RETURNS (num integer)


AS
BEGIN
SELECT count(*)
FROM T_CUSTOMER c, T_BORROWING b, T_EXEMPLAR e, T_FILM f
WHERE c.customer_id=:id
and c.customer_id=b.customer_id
and b.exemplar_id=e.exemplar_id
and e.film_id=f.film_id
INTO :num;
SUSPEND;
END
^

CASE Studio 2 – manual http://www.casestudio.com 50/98


CHARONWARE
database design/modeling tools

/* Update trigger for T_BORROWING */

Create Trigger tu_T_BORROWING


for T_BORROWING before update as
declare variable numrows integer;
declare variable maxcard integer;
begin

/* Restrict child T_BORROWING, when reference to parent T_CUSTOMER is updated */

if (new.customer_id is not null) then


begin
select count(*)
from T_CUSTOMER
where new.customer_id = T_CUSTOMER.customer_id
into :numrows;
if (numrows = 0) then
exception except_upd_ch;
end

/* Maximum cardinality of T_BORROWING cannot be exceeded */

if (new.customer_id is not null) then


begin
select count(*)
from T_BORROWING
where new.customer_id = T_BORROWING.customer_id and new.customer_id <>
old.customer_id
into :maxcard;
if (maxcard >= 5) then
exception except_upd_ch_card;
end

/* Maximum cardinality of T_BORROWING cannot be exceeded */

if (new.exemplar_id is not null) then


begin
select count(*)
from T_BORROWING
where new.exemplar_id = T_BORROWING.exemplar_id and new.exemplar_id <>
old.exemplar_id
into :maxcard;
if (maxcard >= 1) then
exception except_upd_ch_card;
end
end
^

/* Insert trigger for T_BORROWING */

Create Trigger ti_T_BORROWING


for T_BORROWING before insert as
declare variable numrows integer;
declare variable maxcard integer;
begin

/* Restrict child T_BORROWING, when a new ref. to parent T_CUSTOMER is inserted */


if (new.customer_id is not null) then
begin
select count(*)
from T_CUSTOMER
where new.customer_id = T_CUSTOMER.customer_id
into :numrows;
if (numrows = 0) then
exception except_ins_ch;
end

/* Maximum cardinality of T_BORROWING cannot be exceeded */

if (new.customer_id is not null) then


begin
select count(*)
from T_BORROWING
where new.customer_id = T_BORROWING.customer_id
into :maxcard;
if (maxcard >= 5) then
exception except_ins_ch_card;
end

CASE Studio 2 – manual http://www.casestudio.com 51/98


CHARONWARE
database design/modeling tools

/* Maximum cardinality of T_BORROWING cannot be exceeded */

if (new.exemplar_id is not null) then


begin
select count(*)
from T_BORROWING
where new.exemplar_id = T_BORROWING.exemplar_id
into :maxcard;
if (maxcard >= 1) then
exception except_ins_ch_card;
end
end
^

Create Trigger tri_BORROWING


for T_BORROWING after insert as
declare variable price float;
begin
select price_per_one_day
from T_EXEMPLAR
where T_EXEMPLAR.exemplar_id = new.exemplar_id
into :price;
update T_BORROWING set total_price=(end_date-start_date)*:price where
T_BORROWING.exemplar_id=new.exemplar_id;
end
^

Create Trigger tru_BORROWING


for T_BORROWING after update as
declare variable price float;
declare variable total_price_old float;
declare variable end_d date;
declare variable start_d date;
begin
select price_per_one_day
from T_EXEMPLAR
where T_EXEMPLAR.exemplar_id = new.exemplar_id
into :price;
select total_price, end_date, start_date
from T_BORROWING
where T_BORROWING.exemplar_id=new.exemplar_id
into :total_price_old, :end_d, :start_d;
if (total_price_old is null) then
total_price_old=0;
if ((end_d-start_d)*price != total_price_old) then
update T_BORROWING set total_price=(end_date-start_date)*:price where
T_BORROWING.exemplar_id=new.exemplar_id;
end
^
set term ;^

update RDB$RELATIONS
set RDB$DESCRIPTION = 'Borrowed items'
where RDB$RELATION_NAME = 'T_BORROWING';
update RDB$RELATIONS
set RDB$DESCRIPTION = 'All records are stored in list of records. It will be possible
to book a movie.'
where RDB$RELATION_NAME = 'T_ORDER_RECORD';
update RDB$RELATIONS
set RDB$DESCRIPTION = 'Movie ratings (by customers)'
where RDB$RELATION_NAME = 'T_CUSTOMER_RATING';

insert into T_GENRE values (1,'sport');


insert into T_GENRE values (2,'documentary');
insert into T_GENRE values (3,'romantic');
insert into T_GENRE values (4,'horror');
insert into T_GENRE values (5,'action');

insert into T_MEDIUM values (1,'CD - DivX');


insert into T_MEDIUM values (2,'CD - VideoCD');
insert into T_MEDIUM values (3,'DVD');
insert into T_MEDIUM values (4,'Videotape');

insert into T_FILM values (3,'film3','producer3','production_company3',3,15,null);


insert into T_FILM values (2,'film2','producer2','production_company2',5,18,3);
insert into T_FILM values (1,'film1','producer1','production_company1',5,15,2);
insert into T_FILM values (4,'film4','producer4','production_company4',2,0,null);
insert into T_FILM values (5,'film5','producer5','production_company5',4,18,null);
insert into T_FILM values (6,'film6','producer6','production_company6',5,15,null);

CASE Studio 2 – manual http://www.casestudio.com 52/98


CHARONWARE
database design/modeling tools

insert into T_EXEMPLAR values (1,1,3,3);


insert into T_EXEMPLAR values (2,1,3,3);
insert into T_EXEMPLAR values (3,1,3,3);
insert into T_EXEMPLAR values (4,1,4,2);
insert into T_EXEMPLAR values (5,1,4,2);
insert into T_EXEMPLAR values (6,2,3,3);
insert into T_EXEMPLAR values (7,2,4,2);
insert into T_EXEMPLAR values (8,3,3,3);
insert into T_EXEMPLAR values (9,4,4,2);
insert into T_EXEMPLAR values (10,5,3,3);
insert into T_EXEMPLAR values (11,6,4,2);
insert into T_EXEMPLAR values (12,6,4,2);

insert into T_CUSTOMER values (1,'name1','address1');


insert into T_CUSTOMER values (2,'name2','address2');
insert into T_CUSTOMER values (3,'name3','address3');
insert into T_CUSTOMER values (4,'name4','address4');
insert into T_CUSTOMER values (5,'name5','address5');

insert into T_BORROWING (exemplar_id,customer_id,start_date,end_date) values


(11,1,'1.1.2004','3.1.2004');

insert into T_BORROWING (exemplar_id,customer_id,start_date,end_date) values


(12,2,'2.1.2004','10.1.2004');

insert into T_BORROWING (exemplar_id,customer_id,start_date) values (1,2,'6.1.2004');


insert into T_BORROWING (exemplar_id,customer_id,start_date) values (6,4,'7.1.2004');
insert into T_BORROWING (exemplar_id,customer_id,start_date) values (7,3,'7.1.2004');
insert into T_BORROWING (exemplar_id,customer_id) values (9,3);

insert into T_ORDER_RECORD values (1,2,'1.1.2004');


insert into T_ORDER_RECORD values (1,1,'1.1.2004');
insert into T_ORDER_RECORD values (2,2,'3.1.2004');
insert into T_ORDER_RECORD values (3,3,'6.1.2004');

The script has just been generated and saved to your hard drive. To create the
database physically, you will have to run the script via any third party tool (for
example via the CHARONWARE's Foxy SQL Free product).

The model is available at: http://www.casestudio.com/download/addins/videorental.zip

Creating Alter scripts


From time to time you might need to modify your database and generate Alter scripts.
Unfortunately, CASE Studio 2 does not support Alter scripts. It would be a very nice
feature, however it is a more complicated process than it seems to be. As you already
know, the CASE Studio 2 product supports various database systems. Imagine, how many
the variety of changes might be done by the users of so many systems. It is very difficult to
think about all possible changes and tune the software to work perfectly. It might also be the
reason, why the "Alter scripts" support was not integrated into some hi-priced competitive
products.

CASE Studio 2 – manual http://www.casestudio.com 53/98


CHARONWARE
database design/modeling tools

Generating HTML/RTF reports, exporting diagrams

Creating documentation
After you create an Entity Relationship Diagram (regardless of whether the model was
created via Reverse engineering or from scratch), you will certainly need to
generatedocumentation. CASE Studio 2 provides you with a powerful documentation tool.

CASE Studio 2 – manual http://www.casestudio.com 54/98


CHARONWARE
database design/modeling tools

Selecting output and generating reports


The output document can be any one of the following:

• An HTML report of a logical view


• An HTML report of a physical view
• An RTF report of a logical view
• An RTF report of a physical view
• An HTML report of a Data Flow diagram.
• An RTF report of a Data Flow diagram
• An HTML report of your To-Do list
• An RTF report of your To-Do list
• A Version comparison HTML report (accessible via Version comparison)
• A Version comparison RTF report (accessible via Version comparison)
• An User Permission HTML report
• Any other User Defined Report (can be created via Templates Editor)

To generate HTML reports, click the File menu and select HTML report (or RTF report for
RTF format). A following dialog opens.

CASE Studio 2 – manual http://www.casestudio.com 55/98


CHARONWARE
database design/modeling tools

Select a type of HTML report (Logical, Physical, To-Do, DFD), localized report version (by
default only English and German versions are available, other language versions are available
at http://www.casestudio.com), define the Output path and enable/disable the Use style
option. If you enable this option and select a style from the „Others“ drop down menu, a
CSS style will be used and the design will be defined accordingly to the selected style.

This way you can generate the same report in different styles. When you are done, click the
Settings tab. Specify all settings and select whether the report should be generated for the
main model or only for selected submodel. Click Generate to generate the report. For
viewing the report click View. The same steps do for the RTF report generating.

CASE Studio 2 – manual http://www.casestudio.com 56/98


CHARONWARE
database design/modeling tools

Changing the diagrams' look and saving models

Setting background colors and fonts


You can change background color of the whole model or of
any entity. From version 2.15 onwards, it is also possible to
colorize relationship lines. To change the background color of
a model, click View and select Background. Define new color
and click OK to confirm changes. To change the color of one
or more entities, please select the entity and right click on it.
Select the Background color item, define new color and click
OK.

If you want to change the font for your model, click the View
menu and select Font. Select new font and click OK to
confirm changes. (Selecting different fonts for individual
entities is not possible.)

Displaying relationship lines and names


Relationship lines may be displayed as 90° angled or straight lines. To enable/disable straight
relationship lines, click the View menu and select the Straight Relationship Lines item. You
can also show or hide relationship names. To show or hide the names, click the View menu
and enable or disable the Display Relationship Names item.

CASE Studio 2 – manual http://www.casestudio.com 57/98


CHARONWARE
database design/modeling tools

Adding break-points to relationship lines


CASE Studio 2 allows you to add break-points to relationship lines. Enable the Straight
relationship lines mode (View -> Straight relationship lines). Press CTRL, hold it on, move
your mouse cursor over a relationship line and click on it. New break point will be added to
the relationship automatically. You can move the break-point to new position immediately
(CTRL+mouse still active) or later (drag and drop).

Removing break-points from relationship lines


To remove a break point from a relationship line, press CTRL, move your mouse cursor
over the break-point and click on it. This way you can remove break-points one by one.

To remove all break points from particular relationship line, right click on it and select the
“Remove break-points“ item.

CASE Studio 2 – manual http://www.casestudio.com 58/98


CHARONWARE
database design/modeling tools

Moving relationship lines


If you drag a relationship (must have break-points) and move it to another position, all break
points will get the new position. Entities will remain in the same position.

Moving entities
If you move an entity to a new position, the relationship line will be connected to the closest
side of the entity. See the picture below. If we move the Flight plan entity directly under the
Flight route entity, the relationship line will be connected to the right side of the Flight plan
entity.

Note: one break point has been removed from the Relation4 relationship.

Of course, if you select multiple entities and move them to a new position, all selected
entities and their relationships will be moved accordingly.

CASE Studio 2 – manual http://www.casestudio.com 59/98


CHARONWARE
database design/modeling tools

Displaying entities
Entities can be displayed in several modes. Available display modes (physical and logical
views) and display levels (entities, primary keys, keys, all attributes, indexes) were explained
earlier, other settings you can enable or disable are as follows:

• shadow – displays a shadow around entities


• full rolenames – shows exact names of rolenames
• attributes syntax highlighting – displays primary keys in red, foreign keys in green
and primary foreign keys in blue color
• align in columns – shows attribute names, not null constraints and data type
information aligned in columns
• dictionary types – displays names of used user defined data types

Saving models
To save a model, use the File -> Save menu, or use the „Save As“ option.. You can also
export a model into XML file format. XML files can be easily converted into any other XML
format file, HTML file etc. via XSLT. Of course, CASE Studio 2 allows you export a model
into XML as well as load XML files and create entity diagrams automatically.

To export a model into XML file format, click the File menu and select Export. You will be
asked to define the path and provide a name for the XML file. CASE Studio 2 saves XML
files with suffix DMX, however, if you try to open DMX file in for example Notepad, you
will see the XML document structure.

A model can be also saved via the Version Manager -- will be discussed later.

CASE Studio 2 – manual http://www.casestudio.com 60/98


CHARONWARE
database design/modeling tools

Reverse Engineering

Using the Universal Reverse Engineering


CASE Studio 2 is available in two versions – LITE and FULL. The Full Version includes
features like Reverse Engineering. Most of the following text describes the Full version
features, with the exception of the Model explorer feature, for example. One of the most
important and useful features of the Full version is the Universal Reverse Engineering. This
feature allows you to load already existing database structures and create new entity-
relationship diagrams. Almost everything you can model in CASE Studio 2 can be also
reverse engineered (indexes, comments, triggers, relationships, constraints, generators,
functions, views, procedures, user types etc. etc.). The Universal reverse engineering
feature enables you to reverse engineer almost twenty database systems. Moreover, CASE
Studio 2 allows you to write your own reverse engineering.

To reverse engineer a database, click the File menu, select Reverse engineering and choose
the Universal reverse engineering item. A new dialog opens.

CASE Studio 2 – manual http://www.casestudio.com 61/98


CHARONWARE
database design/modeling tools

Selecting a database
First, select the appropriate reverse engineering script. Select the appropriate script (for
Oracle9i database please select the Oracle9i script) from the Execute script drop down
menu. You can currently choose one of the following databases:
• Advantage Database Server 8, 7
• Access 2000
• Access 97
• DB2 UDB version 8 (incl. v. 8.2)
• DB2 UDB version 7.1
• DBISAM 3
• Firebird 1.5
• Informix 10, Informix 9
• InterBase 7 (incl. 7.5)
• InterBase 6 SQL 3
• InterBase 6 SQL 1
• MS SQL 2005, 2000
• Max DB 7.6
• mySQL 5.0 RC, 4.1, 4.0, 3.23
• Oracle 10g, Oracle 9, Oracle 8, Oracle 7
• Pervasive v9, Pervasive V8
• PostgreSQL 8.1, 8.0
• PostgreSQL 7.4
• PostgreSQL 7.3
• Sybase Anywhere 9
• Sybase ASE 12.5.3, 12.5.2, 12.5.1, 12.5
• Sybase ASE 15

Connecting to a database
After you select the script, define
connection settings. Select a
connection method from the
“Connection via” drop down menu.
You can establish connection to the
database via:

• native connection (DB2, Oracle...)


• ODBC (Pervasive, mySQL...)
• ADO (Informix, MS SQL...)
• DAO (for MS Access databases)

After you select the connection method, click the Set Up icon (next to the Connection
via drop down menu) and specify appropriate connection settings. The settings are database
and connection method dependent, so please see the CASE Studio 2's Help file and/or
Documentation to your database for more information on how to configure the connection.

CASE Studio 2 – manual http://www.casestudio.com 62/98


CHARONWARE
database design/modeling tools

Selecting items
Click the tab Settings on the
right side of the dialog and
enable or disable options
related to items you wish to
reverse engineer. The options
are database dependent. For
Oracle models, you can, for
example, decide whether
Sequences or Synonyms
should be loaded, for Firebird
database structures you can
decide whether Blob filters or
External functions should be
reverse engineered. When
you are done with selecting
items, click the Connect
button and establish the
connection.

Selecting tables
After the connection is
established, the software
displays a list of all available
entities. The tab Tables is
active and you can select
tables by checking
appropriate check boxes.
The dialog also includes two
drop down menus. The first
menu allows you to select
one of multiple loaded
databases (this case is
available only for DBIsam
models) and the second
menu allows you to select all
entities which belong to the
same owner.

After you select the entities, click Execute. CASE Studio 2 now creates a new entity
relationship diagram based on the existing database structure. Click Disconnect to close the
connection.

CASE Studio 2 – manual http://www.casestudio.com 63/98


CHARONWARE
database design/modeling tools

Saving settings as Aliases


All settings you have just set can be saved as Aliases
and used again - later. Aliases are very useful because
you will not have to define the connection strings
again and again.

Write any name into the Alias input field and click the
Save icon to save your settings under the new alias.

Using the Layout feature


CASE Studio 2 includes a new autolayout feature.
Press F6 to re-arrange your entities in the diagram automatically. Of course, you ou
can re-arrange entities also manually - and save the layout then. If you reverse engineer the
same database again and apply the previously saved layout, all similar objects will be re-
arranged accordingly.

To save or load the layout, click the Model menu and select Layout -> Save or
Layout -> Load. Layout files have suffix *.la2.

The Layout feature is also very important for maintaining logical names of entities!

Reversing unsupported databases via ADO


CASE Studio 2 also allows you to load unsupported databases via ADO. The result will not
be perfect, however, the possibility of retrieving the design exists. To load unsupported
databases, click the File menu, select Reverse engineering and choose the Unsupported
databases item. Define appropriate settings and click Run to execute the reverse
engineering.

Reversing older databases


Older databases can be reverse engineered by CASE Studio 2. Click the File menu, select
Reverse engineering, choose Older databases and click on appropriate item. Define settings
and click Run to execute the reverse engineering.

CASE Studio 2 – manual http://www.casestudio.com 64/98


CHARONWARE
database design/modeling tools

Maintaining Models

Using the Gallery


CASE Studio 2's gallery is designed to store the most frequently used parts of diagrams -
entities, whole groups of entities, including attributes, relationships, and other predefined
values. Sometimes you need to save a part of a model, or just one entity "aside", for later
use in different models.

Lets say you've just created entity


“Address book” with 20 attributes.
You plan to use such entity in
multiple models and that's why it is
a good idea to include this entity
into the Gallery. To add a new item
to the Gallery, select the entity (or
multiple entities), right click on it
and select the Add To Gallery
option. The Gallery Item dialog box
appears. On tab Properties, fill out
the gallery item name (name), your
name (author), database (this item
will be inserted automatically) and
appropriate notes, if you like. Then
click the Structure tab and see the
structure. Click OK to confirm
changes.

To see the content of the Gallery,


press F11 or click the Dictionary
menu and select Gallery.

Now create a new model and display the Gallery (press F11). Use Drag and Drop to copy
the item from the Gallery to the new model. As you can see, the Gallery can be used as a
“repository”.

CASE Studio 2 – manual http://www.casestudio.com 65/98


CHARONWARE
database design/modeling tools

Using the Model explorer


For a view of all objects, press CTRL+E or click the Model menu and select Model
Explorer. Adialog, with seven tabs opens.

• tab Tree – shows all elements of the model in a tree (inc. basic Model
properties)
• tab Entities – shows all entities. You can sort the items by Entity name or Table
name. To sort entities, click appropriate column name. Sorting entities is not the
only action you can do. It is also possible to edit the items directly. To edit any
entity, double click on its name
• tab Attributes – similarly to entities, also attributes can be sorted and edited
• tab Relationship – also relationships can be sorted or edited
• tab Dictionary – shows the used dictionary items. Sorting and editing items is
available
• tab Indexes – indexes can be sorted, but cannot be edited
• tab Alternate keys – also alternate keys can be sorted, but cannot be edited
directly.

CASE Studio 2 – manual http://www.casestudio.com 66/98


CHARONWARE
database design/modeling tools

Working with a To-Do list


CASE Studio 2 belongs among the first ERD software products into which the To-Do list
feature was implemented. The To-Do list feature allows you to write tasks (or information
about unfinished actions) related to the model. You can assign items to:

• Model
• Entity
• Relationship
• Dictionary
• Triggers
• Users
• User roles

To add a new to-do list item to the model, press CTRL+ALT+T or click the Model menu
and select To-Do list. A new dialog opens.

Click the + (plus) button to create a new item. Click tab To-Do and write text into the
largest text area. To the field Owner, write the item's owner name. To the Category field,
write a new category name. You can also set a priority for the item and define a creation
date. The check box “Done” allows you to mark the item as accomplished.

To erase a To-Do list item, click the – (minus) button.

You are allowed to assign items to different objects. We know, how to assign a To-Do list
item to the Model, however, the same method cannot be used for assigning item to Entities
or Relationships, for example. In general, you can access the To-Do list dialog from various
dialogs. Edit any entity and see the To-Do list button at the bottom. Then edit any
relationship and see the same button on this dialog.

It is very important, from where you access the To-Do list feature. If you click the To-Do list
button when editing your existing Entity, the To-Do list item will be assigned to the opened
Entity. If you click the To-Do list button when editing existing relationship, the To-Do list
item will be automatically assigned to the currently edited Relationship.

CASE Studio 2 – manual http://www.casestudio.com 67/98


CHARONWARE
database design/modeling tools

The To-Do list dialog includes several display modes:

• O - Displays items related to currently selected Object (selected entity)


• A - Displays items related to All objects (all objects in the model)
• C - Displays items related to the same object Category (all entities)
• D - Displays items Dependent on the selected object (relationships and
attributes which belongs to a selected entity)

See the following screen shots, both show items related to the currently opened entity:

Only items related to this Object All items

Of course, you can also manage your To-Do list. Click the Set up icon to access the To-do
list maintenance dialog. You can delete unassigned or finished items. Click the Clear button
to execute the deletion.

The To-Do list can be also exported to an HTML or an RTF format report. Click the File
menu and select the HTML or RTF report item. Define appropriate settings and generate
the report.

CASE Studio 2 – manual http://www.casestudio.com 68/98


CHARONWARE
database design/modeling tools

Automatic model conversion


CASE Studio 2 cannot convert diagrams automatically, however, it can help you with the
conversion. Since triggers, stored procedures, functions, generators and other text objects
are database specific items (every database uses different languages and different methods),
it is not possible to convert them automatically (converting text objects from one database
system to another could be compared to converting source codes from C++ to VB, for
example.).

Supported Text objects cannot be parsed, you will have to modify them manually after the
conversion is done. CASE Studio 2 can convert the data types used in the model, and you
can define appropriate rules for the data type conversion. For example, if you need to
convert data types from Oracle 8 to Firebird, click the Model menu and select the Database
conversion item. From the “Convert to” drop down menu please select the database
system to which you wish to convert your model.

Next select items you wish to convert (indexes, triggers, views etc. - warning, the items will
only be moved in untouched form) and then click the Setup button.

The Database Conversion Setup dialog opens. If you are not satisfied with the default
settings, modify any check box and select new data types from the “To” column.

CASE Studio 2 – manual http://www.casestudio.com 69/98


CHARONWARE
database design/modeling tools

When you are done, click the OK button to confirm your changes. Click the Convert button
to run the conversion. Of course, remember to edit Text objects and make appropriate
manual changes to Views, Triggers etc.

CASE Studio 2 – manual http://www.casestudio.com 70/98


CHARONWARE
database design/modeling tools

Using the Version manager

Creating a project
The Version manager allows you to manage your models. You can create an entity
relationship diagram, save it into the version manager, modify the model and save the
diagram as new version or revision. Later, you can compare two versions and generate
appropriate HTML or RTF reports, describing the changes.

To add a model into the Version manager do the following:

• Create a new model or open an existing one.


• Click the Model menu and select the “Insert Model into Version manager” item. A new
dialog opens.
• Click the yellow folder icon and create a new project file (you can select the numbering
method – in our example, we will start with number 1.0). The file will be saved with
suffix *.DP2. Now you have three windows in CASE Studio 2. The original model, the
1.0 model and the dialog Versioning. Close the original and the 1.0 models, keep only the
Versioning dialog active. Click the 1.0 model name in the dialog and specify settings on
tab Detail. You can assign a version name (CASE Studio 2 uses the name as a part of the
model name, so it will no longer be named as 1.0, but as 1.0 – VersionName.), version
number, date of creation and date of modification.

Note: On the Detail tab, there is also a specific number at the bottom (for example:
04231727.DV2) The number represents the physical file name of the version. CASE Studio
2 stores all project files to the same folder, where the project (file *.DP2) is stored. If you
rename any of the *.DV2 files to *.DM2 (standard CS2 file format), you will be able to open

CASE Studio 2 – manual http://www.casestudio.com 71/98


CHARONWARE
database design/modeling tools

the diagram directly. Warning: Do not erase the *.DV2 files from the folder where the main
project is saved. The *.DV2 files are not temporary files, but separate project files !

After you specify the version name, click the “Out” button (as in “Check Out”) to open the
1.0 model. See the Versioning dialog. As long as no change is done to the 1.0 model, the
arrow left to the version name (in tree) remains blue. Immediately after you make a
modification to the 1.0 model the arrow turns red. Do any modification, for example add a
new entity to the model and try to close the model (you can close the model in a standard
way or by clicking the “In” button. In both cases, you will be asked to save the model to:

• the current revision - the file will be modified and stored as version1.0
• a new revision - the file will be stored as version 1.1
• a new version – the file will be stored as version 2.0

Comparing versions
Any version can be compared to any other previous or following version. Open a model
from your Project and make it active. From the Model menu select the item Compare
models. A new dialog opens.

The dialog includes one large drop down menu. Choose any previous or following version of
the model from the top sided drop down menu and see the differences between the
currently opened model and the model you have just chosen. The overview tree displays all
changes and on the right side, there is a detailed grid of all items. You can double click any
item for editing the modified items.

A detailed instructional movie is available at http://www.casestudio.com

You can also compare two independent diagrams. To do that, open a model, click the Model
menu and select the Compare versions item. A new dialog appears.

Click the Open file icon and select a model you wish to compare to the currently opened
model. It is recommended to compare two models of the same target database only.

CASE Studio 2 – manual http://www.casestudio.com 72/98


CHARONWARE
database design/modeling tools

Two versions or two independent models may be compared by GUI, by Name or Physical
name. If you rename any entity, its GUI will not be changed. Therefore it is recommended
to compare two versions in various ways.

If you compare two independent models (two *.dm2 files), do not use the comparison by
GUI as all items have unique GUIs. Compare the two models by Name or Physical name,
instead.

Generating HTML/RTF reports


CASE Studio 2 enables you to generate HTML and RTF version comparison reports. To
generate a report, compare two models and click the HTML or RTF icon. Define
appropriate settings and click Generate.

CASE Studio 2 – manual http://www.casestudio.com 73/98


CHARONWARE
database design/modeling tools

Configuration

Environment setup
To configure global settings for CASE Studio 2, click the File menu and select Environment
Setup. A new dialog appears.

• Desktop tab – a place where default display mode, desktop background color, font,
zoom and other settings can be defined. All settings are valid for all newly created
models.

• Directories tab– a place where default program paths can be re-defined. This tab also
includes additional options as for example XML header specifications. Pay attention to
the following options:

• Lock models – enable this check box to lock your models. Locked models can be
opened at the same time by one person only and therefore cannot be modified
or re-written by any other user.

CASE Studio 2 – manual http://www.casestudio.com 74/98


CHARONWARE
database design/modeling tools

• Load additional database templates – enable this check box to instruct CASE
Studio 2 to load additional database template files. Additional database template
files are XML format documents saved as .TA2 files which includes a description
of currently unsupported database system (e.g. NexusDB). This topic will be
discussed later.

• Run only one instance of CASE Studio 2 – enable this check box to run only one
instance of CASE Studio 2.

• Text Editor tab - a place where default text editor type can be selected. Available
options: Internal, External, Associated.

• Synchronization tab - a place where synchronization rules can be defined. First, select
a level of synchronization. Available options are:

• None – if you select this option and create a relationship, no data which belongs
to the primary key will be assigned to the foreign key.
• Partial - if you select this option and create a relationship, selected data (as for
example Unique constraint names etc.) which belong to the primary key will be
assigned to the foreign key.
• Complete - if you select this option and create a relationship, all data which
belong to the primary key will be assigned to the foreign key (and you will not be
allowed to change them manually).

When you are done with setting up the level of synchronization, choose additional
appropriate settings. Table name synchronization – entity and table names will be
synchronized in accordance to the defined settings. The same system works for attribute
and column names (field name synchronization) names used in user defined dictionary
items (physical names synchronization of dictionary items) and primary key constraint
names (constraint synchronization of primary key). Feel free to re-define the default
values at any time. You can set the settings back by pressing the Default values button.
(More information can be found in the CASE Studio 2's help file.)

• Integrity tab - Select the style of referential integrity which you wish to implement. The
settings will affect only new models.

• Version manager tab - Select how you will save files in the Version manager.

• Syntax highlighting tab - Select colors for comments and strings here.

• Scripting tab - a place where default Scripting language version can be defined. The
English language version is the default value. This option affects the scripting language
only, so if you select for example German scripting language version and try to generate
an HTML report, CASE Studio 2 will not offer you the English HTML report as a default
option, but rather the German HTML report. This option has nothing to do with the
programming interface or software language version. On the Scripting tab, there is also a
check box called “Execute event OnAppStart”. It is necessary to enable this check box
in order to run specific user defined templates. This option will be explained later, in the
topic related to the internal Templates Editor.

CASE Studio 2 – manual http://www.casestudio.com 75/98


CHARONWARE
database design/modeling tools

Model properties
Right click the desktop area and select Model Properties to reach the Model Properties
dialog.

• Properties – a place where information like Model name, Author name, Model version
and other can be defined. The values will be used in the Stamp, when placed in the
model.

• Notes – a place where notes about the model can be written.

• Settings – Synchronization rules can are defined here. These options have a higher
priority than the options specified in the Environment Setup dialog. All modifications will
take effect immediately. Also on this tab the Default data type can be specified, as was
explained earlier. Another option you can enable or disable is the Partiality and Not Null
values synchronization. Enable this check box to synchronize Not Null values with
defined Partiality.

• Default Values tab – a place where implicit values can be defined. All settings are valid
for new items, options Display Level, Default Background, Shadow, Full Rolename,
Physical View and Zoom Level for new submodels only (if you create a new submodel,
the defined values will be used).

CASE Studio 2 – manual http://www.casestudio.com 76/98


CHARONWARE
database design/modeling tools

• Checks tab – Default values for model verification can be specified.

• Advanced tab – Defined variables related to a model can be specified. User defined
variables will be described later, in topic Templates Editor.

• Statistic tab – Model Statistics can be viewed here.

• Default Storage – Default storage parameters can be defined here.

Extended settings
Three items are available in the Extended settings menu:

• Conversion between databases – Click the File menu, select Extended settings and
choose the Conversion between databases item. A new dialog opens. Define rules for
the Model Conversion feature and click OK to confirm changes. All settings were
explained in the topic related to the Model Conversion feature.

• Patterns – Click the File menu, select Extended settings and choose the Patterns item.
Define new patters for triggers, stored procedures and view and save the settings. See
the previous explanations for this topic.

• Available databases – Click the File menu, select Extended settings and choose the
Available databases item. A new dialog opens. Enable the check boxes related to the
databases you work with and confirm changes. If you try to create a new model, only
enabled databases will be displayed in the Target Database Selection dialog. (See the
icon: if the light is turned on, it is recommended to have the check box enabled.)

CASE Studio 2 – manual http://www.casestudio.com 77/98


CHARONWARE
database design/modeling tools

Extending CASE Studio 2

Using the Templates Editor


Via the Templates Editor, you can add new features to CASE Studio 2, support currently
unsupported databases and more. You can, for example, affect the generation of SQL
scripts, create custom reports, add items into the main menu, etc.

To open the Templates Editor, click the Model menu and select the Edit Templates item or
press CTRL+L.

CASE Studio 2 – manual http://www.casestudio.com 78/98


CHARONWARE
database design/modeling tools

Introduction to the Templates Editor's interface


To open the Templates Editor, click the Model menu and select the Edit Templates item or
press CTRL+L. The Templates Editor allows you to manage:

• Templates – scripts, parts of scripts, macros and functions. Click tab Templates
to display the dialog related to templates. On the left side, there is an overview
tree of all templates, on the right side, you can find settings related to selected
template. Properties are described in the Help file which is distributed together
with the software.
• Editors of Variables – you can add new variables to CASE Studio 2 and use
them for any purpose. You will need to make your variables accessible and for
that purpose you can create new Variable Editors. If you create a new Editor,
then the item will be available on the appropriate Advanced tab (of dialog Entity
or Relationship etc.).
• Packages – packages are ideal for distribution of templates. You can export
multiple templates as a package and publish the package on your web site or
pass the package on to your co-workers. It is also easier to erase packages as
you don't have to delete all the templates individually. Click the Packages tab to
manage Packages.

Templates - sections explanation


You can create new features for all target databases (global features), or, for a particular
database engine (features only for My SQL for example) as well as new HTML or RTF
reports etc. For easier orientation and navigation, CASE Studio 2's Templates Editor allows
you to store templates under several specific sections:

• Default – general folder (obsolete).

• System templates – a place where system templates which affect all


target databases are stored. System templates which have icons with red
header, cannot be modified directly, but can be copied to the “User
defined system templates” section and modified afterwards.
• User defined system templates – a place where modified system
templates (or new templates) related to all target databases should be
stored. Note: User defined system templates have a higher priority, but
only in case that both, the original system template as well as the user
defined template have the same name.
• Database templates – under each template section is a Database
heading which holds templates related to the currently selected target
database. (database templates have higher priority than system
templates)
• User defined database templates – a section where all modified
Database templates should be stored. If you select for example, Oracle
9i as the target database, you can create a new template and store the
template code under this section, the new feature will be available only

CASE Studio 2 – manual http://www.casestudio.com 79/98


CHARONWARE
database design/modeling tools

for all Oracle 9i models. (Not for IBM DB2, Firebird etc.)
• Model templates – a section for all templates related to the currently
selected model.
• Entity templates – users are allowed to create templates also for any
particular entity. All templates related to the selected entity should be
stored in this section, under the appropriate entity name.
Note: a template stored in higher section has higher priority.

• Global – a section under which all dictionary templates, language specification


templates and other global level templates of CASE Studio 2 should be stored.
• Database – a section where templates for SQL script generation should be
stored. If you wish to add a new feature for MySQL databases only, store your
new template in User defined database templates section.
• HTML reports – a section under which all templates related to HTML report
generation should be stored.
• RTF reports – a section for all Rich Text Format (RTF) related templates.
• Events – a place where all executable templates should be stored. For example,
if you wish to add a new menu item into the CASE Studio 2 file menu, store your
template here.
• Reverse engineering – a section where all templates related to the Reverse
engineering features should be stored.
• Model verification – a section where model verification templates should be
stored.
• Model comparison HTML reports – a section where all templates affecting
the generation of Model comparison HTML reports should be stored.
• Model comparison RTF reports – a section where all templates related to
generating of Model comparison RTF reports should be stored.

Note: All system templates are stored in file CaseStud.ts2 and all user defined templates
are stored in file CaseStud.tu2, both files are XML format documents and can be found in
the BIN folder. (One Possible path is: C :\program files\rkscase\casestudio\bin if you used
the default installation settings). If you install a new version of CASE Studio 2, the system
will override the CaseStud.ts2 file. User defined templates will remain untouched.)

Importing templates
You can find additional templates at http://www.casestudio.com. On these pages you can
freely download the latest version of the system template, as well as other additional
templates, in *.te2 format designed for the CASE Studio 2 program. To import the published
user defined templates and add-ins, do the following:

1. Select an appropriate target database


2. Choose the menu items: Model --> Edit templates
3. Choose Templates --> Import templates
4. Click the Open file icon and select the template
5. Click the Execute icon (yellow flash icon)
6. Close the Templates and Variable Import dialog

CASE Studio 2 – manual http://www.casestudio.com 80/98


CHARONWARE
database design/modeling tools

Modifying templates
Of course, a task can be done in various ways. CASE Studio 2 allows you to modify system
templates hence you can change, for example, the method of SQL script generation and
other features. If you would like to generate Triggers before Stored Procedures and
Functions, then Change the default order in appropriate system template and then store the
template under the appropriate section!

You have two possibilities how to modify system templates:

New and much faster way of the template modification: NEW !

1) Click Model menu --> Edit Templates. The Templates Editor dialog will open.
2) Select a template and right click on it.
3) Select appropriate item from the pop-up menu.

Note: All parameters of an original template will be copied to a new template, therefore it's
not necessary to check the settings of the new template carefully.

CASE Studio 2 – manual http://www.casestudio.com 81/98


CHARONWARE
database design/modeling tools

Older way of the template modification:

1. Choose Model --> Edit templates (Main menu)


2. Select e.g. User-defined templates (any folder/templates but Read Only)
3. Right click the icon and select ADD
4. Choose a system template from the top positioned drop down menu
5. Click the Copy template button (next to the drop down menu). CASE Studio 2
has just created a copy of the system template
6. Click the Properties tab and make sure all settings of the current template are
identical to the settings of the original system template (A user defined template
has a higher priority only if both templates are of the same name. So, if you want
to override a system template, make sure the settings are identical. If you want
to create absolutely new template based on any system template, make sure the
names are different)
7. Add your own SQL commands
8. Click the OK button to save the template

Creating user defined templates


Creating new User defined templates is not very complicated. For advanced users, familiar
with JScript or any other scripting language it's easy. It is only necessary to know JScript,
VBScript or some other similar scripting language. More information about the internal
scripting languages can be found at http://www.casestudio.com , in Download ->
Documentation section. It is recommended to visit the section and download the
Interfaces.pdf and Iscript.pdf documents.

In the following section, we will create a new template for adding a prefix before
all the column names.

Task: Create a new menu item for all Firebird models. When the menu item is clicked, the
software will add a defined prefix to all column names. Users will be allowed to define the
prefix on the Advanced tab of the Edit Entity dialog.

The method is as follows:

1. Choose Model --> Edit templates to open the Templates Editor

2. Click any User-defined templates folder (any folder/template but Read Only) In our
case, the Events folder.

3. Right click the icon and select ADD

4. Click the Properties tab and enter values

CASE Studio 2 – manual http://www.casestudio.com 82/98


CHARONWARE
database design/modeling tools

Settings:
Executable: The Executable check box must be checked as the template will be called from
the Add-ins menu.

Event: Event is set to OnAppStart because we would like to load this menu item
immediately after the CASE Studio 2 is started. (Note: Also the ckeck box “Execute event
OnAppStart” on tab Scripting of the Environment Setup dialog must be checked!)

5. Click the Text tab and write the script for the template (in our example, JScript is used)

CASE Studio 2 – manual http://www.casestudio.com 83/98


CHARONWARE
database design/modeling tools

See the body of the template:

// function 'Main' adds on start of the application a menu item


// 'Add a prefix to all column names...' into the Add-ins
// menu, that will call script 'OnClick' from the
// 'AttrAddPrefix' template upon it's activation.

function Main()
{
MenuManager.AddMenuItem('&Add a prefix to all column
names...','AttrAddPrefix','OnClick');
};

CASE Studio 2 – manual http://www.casestudio.com 84/98


CHARONWARE
database design/modeling tools

function OnClick()
{
if ((typeof(Model) == 'undefined') || (Model.DatabaseId != 330))
SysUtils.Alert( 'Open or select a model for Firebird before
adding prefixes to column names.' )
else
AddPrefix();

};

// function for adding a prefix before all column names

function AddPrefix()
{
var e,a,add_pre;

// A value of the variable add_pre will be filled by the


// value of CASE Studio 2's User Defined Variable “AddPrefix”.
// This will be explained in next chapter.

Model.ReadOnly = false;

for (e=0; e<Model.CountEntities; e++)


{
Entity = Model.Entities(e);
add_pre = Entity.GetUserVariable('AddPrefix');

if ( (add_pre != '') && SysUtils.Confirm( 'Should I add


the \''+add_pre+ '\' prefix to all column names
in Entity \''+Entity.Name+'\' ?' ) )
{
for (a=0; a<Entity.CountAttributes; a++)
{
Attribute = Entity.Attributes(a);
if (Attribute.ColName.substr(0,add_pre.length) != add_pre)
Attribute.ColName = add_pre + Attribute.ColName;
}
}
};

Model.ReadOnly = true;

Alert( "Finished successfully." );


};

6. Check all additional tabs and enter values


7. Click the OK button to save the template

The template is almost ready to use. The last step we will have to do is defining the User
defined variable AddPrefix.

CASE Studio 2 – manual http://www.casestudio.com 85/98


CHARONWARE
database design/modeling tools

Creating new Variables


Open the Templates Editor, click tab Editor of Variables and notice the four buttons at the
bottom of the dialog.

CASE Studio 2 – manual http://www.casestudio.com 86/98


CHARONWARE
database design/modeling tools

To create a new Variable, click


the ADD button and define
appropriate values:

• Variable – variable name. You


will be able to access this
variable via JScript . Example:
Entity.GetUserVariable
('AddPrefix')

• Description – variable
description. Whatever you write
to this field will be used as a
caption of the Editor (on tab
Advanced of appropriate
dialog).

• Order – order number which


belongs to this item (enter
smaller value to make this item
accessible at first, enter higher
number to make this item
accessible at last)

• Width – editor's width in pixels.


For longer items, enter higher
values.

• Default – default value of the


variable.

• Datatype – text (input field), logical (check box), enumeration (drop down menu).

• Items – available only for enumeration data type items. Add values separated by
commas, closed by quotation marks.

• Availability – select one of the following: model, generator, entity, attribute, index,
relationship, dictionary, alternate key, To-Do item. If you select for example Entity, the
new variable will be accessible on tab Advanced of the Entity dialog.

• Owner – select either Model or User defined template. If you select the Model item,
your editor and its variable will be accessible only for the currently opened model. If you
select User Defined Template, the editor and its variable will be available for all models
of the same target database.

In our example, we will create the AddPrefix user defined variable. On the image above,
you can see that the Availability was set to Entity. That's why the input field “Define prefix”
will be accessible on the Advanced tab of the Edit Entity dialog.

CASE Studio 2 – manual http://www.casestudio.com 87/98


CHARONWARE
database design/modeling tools

The template is now fully functional. Make the template active (select the template) and
click the Red Flash Icon to run the template directly from the Templates Editor dialog, or
restart CASE Studio 2. Edit the entity Customer and on tab Advanced, define the prefix as
CU_. Click the Add-ins menu and select the “Add a prefix to all column names” item.

The script will be executed and the following message will be displayed:

Confirm it by pressing the OK button. Press F5 to refresh the desktop area. You will see,
that the “CU_” prefix was added to all column names.

CASE Studio 2 – manual http://www.casestudio.com 88/98


CHARONWARE
database design/modeling tools

Exporting templates and creating packages


Multiple templates can be exported either as one package or individually as separate *.TE2
files. To export user defined templates, open the Templates Editor, click the Templates
menu and select Export templates. Click tab Export and select the templates you wish to
export. Then click tab Package and enable/disable the check box Export as package. If you
enable this check box, all templates will be exported as one complex package. Of course,
you can define a package name, version of the package as well as you can add information
about the author and his/her company. When you are done, click the Save icon, define the
package name and its destination and save it to your hard drive or any other media.

Publishing packages
User defined templates and packages can be downloaded from the following address:
http://www.casestudio.com/enu/daddins.aspx You will find there some new features, handy
functions and various extensions. User defined templates and packages can be shared with
other CASE Studio 2 users. If you have developed some templates, with that you believe
may be useful to others, and you'd like to share them with other users as well, then you can
send them to templates@casestudio.com.

By sending a template to CHARONWARE, you agree to the following:


• Any user can change/modify the template accordingly to his/her best purposes
and publish it again as a new template.
• Your template will be published and offered for free. No fee or payment will be
required.

Deleting packages
Deleting almost any of CASE Studio 2's objects (entities, relationships, dictionary items,
variables and others) is very easy, because the software interface is relatively intuitive and
you can find the Delete button on appropriate dialogs. However, note the following issues
when deleting packages.

It might be necessary to update your templates or imported templates (packages, Add-ins)


after a new version of CASE Studio 2 is released. The new version could include re-written
or updated system templates and therefore all user defined templates based on system
templates may need to be corrected. The majority of templates and Add-ins published on
CHARONWARE's web site are updated by the CASE Studio 2 team automatically, however,
users are required to import the templates into CASE Studio 2 again. Before you download
and import the updated templates, delete older packages by doing the following:

Open the Templates Editor and click tab Packages. Right click the package name under
section User-Defined packages and select Delete Package to erase the older templates from
CASE Studio 2. Then import the updated packages.

CASE Studio 2 – manual http://www.casestudio.com 89/98


CHARONWARE
database design/modeling tools

Using the MS Scripting window


CASE Studio 2 contains the MS Scripting window for a quick launch of scripts. You can write
short but very powerful scripts and run them in the MS Scripting window directly. Using the
following script, we will convert all attribute and column names to lowercase at once. Click
the Model menu and select the MS Scripting item to call the following dialog.

Write the script to the Script area and click the red flash icon to launch it.
Example: Converting all attribute and column names to lowercase.

function Main()
{
Model.ReadOnly = false;
// change name of tables to lowercase
for (e=0;e<Model.CountEntities;e++)
Model.Entities(e).TableName = Model.Entities(e).
TableName.toLowerCase();
// change name of columns to lowercase
for (a=0;a<Model.CountAttributes;a++)
Model.Attributes(a).ColName = Model.Attributes(a).
ColName.toLowerCase();
Model.ReadOnly = true;
}

Note: Your script must start with function Main(), because CASE Studio 2 executes
this function first. In other words, the function Main() is required!

CASE Studio 2 – manual http://www.casestudio.com 90/98


CHARONWARE
database design/modeling tools

Appendix A - Normal Forms


THE NORMALIZATION GUIDELINES
The normalization guidelines are a set of data design standards called the normal forms.
Five normal forms are widely accepted, although many more than that have been proposed.
Making your tables match these standards is called normalization.
The normal forms progress in order from first through fifth. Each form implies that the
requirements of the previous forms have been met. If you follow normalization rule number
one, your data will be in first normal form. If you follow normalization rule number three,
your data will be in third normal form (and also in first and second normal form).
Following the normalization guidelines usually means splitting tables into two or more tables
with fewer columns, designing primary key-foreign key relationships into the new, smaller
tables so that they can be reconnected with the join operation.
One of the main advantages of splitting tables according to the normalization guidelines is
the reduction of data redundancy within tables. This may seem confusing when the
existence of matching primary key-foreign key hooks means that these columns are
duplicated. But intentional duplication is not the same thing as redundancy. In fact, the
maintenance of intentional duplication (that is, consistency) between primary and foreign
keys is a major point of referential integrity.
The normalization guidelines, like entity-relationship modeling, were developed as part of
the academic work on database theory. While they are extremely useful, they can be
followed too slavishly. Most database designers find that putting their data in third or fourth
normal form is usually as far as they need to go.

First Normal Form


First normal form requires that at each row-and-column intersection, there must be one
and only one value, and that value must be atomic: there can be no repeating groups in a
table that satisfies first normal form.
Where there are repeating columns, the correct design involves (for example) a master
table (saleheaders) for the sales order as a whole and a detail table (salesdetails) to hold
information for individual order lines in the sales order. Notice that entity-relationship
principles would have led to the same conclusion, since this is a one-to-many structure (one
sales order, many lines).

While you're looking at repeating fields, make a note to break up any compound columns
into their elements: address needs to have separate columns for city and state (or province),
for example.

Second Normal Form


The second normalization rule states that every nonkey column must depend on the entire
primary key. Therefore, a table must not contain a nonkey column that pertains to only part
of a composite primary key. Putting a table into second normal form requires making sure
that all the non-primary key columns (the columns that give information about the subject

CASE Studio 2 – manual http://www.casestudio.com 91/98


CHARONWARE
database design/modeling tools

but do not uniquely define it) relate to the entire primary key and not just to one of its
components.
In sum, second normal form requires that no nonkey column be a fact about a subset of the
primary key. it applies when the primary key is made up of more than one column, and is
irrelevant when the primary key is one column only.

Third Normal Form


Third normal form applies the principle addressed by second normal form in a more general
way: it's not limited to composite primary keys. Third normal form requires that no nonkey
column depend on another nonkey column. Each nonkey column must be a fact about the
primary key column.

Fourth and Fifth Normal Forms


Fourth normal form forbids independent one-to-many relationships between primary key
columns and nonkey columns. We'll use the following example as an illustration: one author
can have many cars and many musical instruments, but there is no connection between cars
and instruments even though each is legitimately related to a particular author.

Putting these two different kinds of information in the same table can lead to unsightly
blanks where there are more instruments than cars or more cars than instruments. Deleting
a car or an instrument (if a car dies or an instrument is given away) could also cause blanks
in rows.

The problem here is with the spurious relationship that seems to exist between cars and
instruments by virtue of their positional association in the row. It is better to put each of
these entities in a separate table and to record their relationship to an author by using the
author ID as a foreign key column.

Fifth normal form takes the process to its logical end, breaking tables into the smallest
possible pieces in order to eliminate all redundancy within a table. Tables normalized to this
extent consist of little more than the primary key. Here's an example:

One advantage of putting a database into fifth normal form is control of database integrity.
Since you are assured that each piece of nonkey data (data that is not a primary key or a
foreign key) is likely to occur only once in the database, it's relatively easy to update that
kind of data without worrying about keeping all the duplicates up-to-date. If a book's price
changes, for example, you make an entry in the prices table only. You don't have to scan the
other tables to see if the price appears there.

However, since each table has so few columns, you have to repeat the same keys over and
over in order to be able to join the tables and get meaningful information out of them.
Changing the value of a single key (a particular title-id, for example) is a consistency problem
of a different order. You still have to identify every place where that value exists and make
sure it gets updated. Fortunately, the values in primary key columns tend to change much

CASE Studio 2 – manual http://www.casestudio.com 92/98


CHARONWARE
database design/modeling tools

less frequently than those in nonkey, dependent columns.


If there is a moral, it is this: Attempt to reach a balance between redundant data and
redundant keys.

Boyce-Codd Normal Form


An attribute in a relation (table) is said to be a candidate key for the relation if and only if it
is unique at any given time, and if the attribute is composite (composed of several
sub-attributes). Eliminating any of its components results in destroying the attribute's
uniqueness. According to this definition, every relation has at least one candidate key.
Actually, most relations have just one candidate key, but can have more than one. An
example is the Titles table, in which there is a primary key (ISBN) that is a candidate key,
and another composite candidate key composed of the Book-Title, Book_Edition, and
Publisher-ID.

As originally conceived, the third normal form still had some deficiencies. This form did not
handle certain cases well enough. These cases include relations with the following
characteristics:

• Multiple candidate keys


• The candidate keys were composite
• The candidate keys overlapped (had at least one attribute in common)
A new normal form Boyce-Codd normal form) was introduced to handle these deficiencies.
According to this normal form, every determinant in the relation has to be a candidate key.
In terms of functional dependency, arrows are always going out of the candidate keys-and
only candidate keys.

Note
The reason this normal form was not called a fourth normal form is that it only
extends the third normal form, making it simpler to define, but stronger by
eliminating its deficiencies.

CASE Studio 2 – manual http://www.casestudio.com 93/98


CHARONWARE
database design/modeling tools

Notes:
...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

CASE Studio 2 – manual http://www.casestudio.com 94/98


CHARONWARE
database design/modeling tools

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

CASE Studio 2 – manual http://www.casestudio.com 95/98


CHARONWARE
database design/modeling tools

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

...........................................................................................................................................................

CASE Studio 2 – manual http://www.casestudio.com 96/98


CHARONWARE
database design/modeling tools

Links
CASE Studio 2 homepage:
• http://www.casestudio.com/enu/default.aspx

CASE Studio 2 download:


• http://www.casestudio.com/enu/download.aspx

CASE Studio 2 documentation:


• http://www.casestudio.com/enu/ddocument.aspx

CASE Studio 2 instructional movies:


• http://www.casestudio.com/enu/dmovies.aspx

CASE Studio 2 pricing:


• http://www.casestudio.com/enu/prices.aspx

CASE Studio 2 ordering form:


• http://www.casestudio.com/enu/order.aspx

CASE Studio 2 support:


• http://www.casestudio.com/enu/contact.aspx

CASE Studio 2 forum:


• http://www.casestudio.net/forum/

Sample model Video Rental


• http://www.casestudio.com/download/videorental.zip

Sample template Add a prefix to all column names...


• http://www.casestudio.com/download/addins/ColAddPrefix_Firebird.zip

Sample script To Lower Case


• http://www.casestudio.com/download/scripts/ToLowerCase.zip

CASE Studio 2 – manual http://www.casestudio.com 97/98


CHARONWARE
database design/modeling tools

Acknowledgments
I want to thank to Dave Robinson of PMC Consulting,http://www.pmccl.com Ontario
Canada for his kind contribution (especially for the Appendix A) and for correcting all the
chapters of this manual. He helped to turn my thoughts into a readable form.

I also want to thank Etienne Bar (http://www.sampathdev.com) for commenting on the


manual and introducing the document to French speaking readers.

Finally I want to thank David Fux, Radim Kunz and Radim Mario Tkacik for all the
support and samples.

Tell us what you think


In case you have any question, suggestion or recommendation, please feel free to contact us
at support@casestudio.com. Your feedback is welcome.

Thank you for your time,

Vaclav Frolik
CHARONWARE, s.r.o.

CHARONWARE, s.r.o.
Ulehlova 267/5
700 30 Ostrava
Czech Republic

Email: support@casestudio.com

http://www.casestudio.com

CASE Studio 2 – manual http://www.casestudio.com 98/98

Вам также может понравиться