Table of Contents Previous Section
Derived Attributes
A derived attribute doesn't map directly to a single column in the root table of the entity. A derived attribute can be based on another attribute that's modified in some way, such as an bonus attribute that's the result of a calculation performed on a salary attribute. A derived attribute can also be an aggregate consisting of more than one attribute; for example, you can create a derived attribute fullName that is an aggregate of lastName and firstName.Derived attributes, since they don't correspond to real values in the database, are read-only; it makes no sense to write a derived value.
Adding a Derived Attribute
You can use the concept of derived attributes to add to an entity a new attribute that doesn't correspond to any database column. This attribute can contain a computed value, for example, or an aggregate of multiple attributes.To add a new attribute to your entity:
- In the Model Editor, select the entity (such as Talent) to which you want to add an attribute.
- Choose Property Add Attribute.
- In the Attribute Inspector, edit the Name field to supply a new name for the attribute.
- Use the pop-up list to the left of the Definition field to change the attribute type from Column to Derived.
- Edit the Definition field to supply the SQL needed to specify the derived attribute.
- In the External Type field, add the attribute's data type (VARCHAR2). This should be the data type as it is in the database.
- In the External Width field, type the width constraint for the attribute (this only applies to string and data values).
Alternatively, you can use the button on the toolbar. In either case, a new attribute with the name "Attribute" appears in the entity's list of attributes.
For example, you can create an attribute called fullName that combines the firstName and lastName attributes.
Note that this is a contrived example. A safer way to achieve the same end would be to implement a method on your enterprise object-this would ensure that if the firstName or lastName attribute is modified, the derived attribute fullName will immediately reflect the change.
For example, to concatenate the firstName and lastName attributes in Oracle, type the text:
firstName||' '||lastName
The Sybase equivalent is:
firstName+' '+lastName
Figure 29. Adding a Derived Attribute
Table of Contents Next Section