Tutorials : Relational data modeling for data architecture : Module 1: Generate a logical data model : Lesson 1.2: Draw and define entities and their components
  
Lesson 1.2: Draw and define entities and their components
Draw entities to represent a hotel guest, reservation, room, and vehicle. Define these entities by adding the attributes name and guest number.
Draw entity symbols
Draw the entities for a Guest, Reservation, Room, and Vehicle.
A Guest has a Reservation so they can be assigned to a Room. An alternative way to phrase the situation is "the room belongs to the Guest." The guest can own a vehicle that they want to park in the hotel lot.
To place a new entity symbol
1 In the Tutorial encyclopedia, select the Entity symbol from the Draw toolbar and click the diagram workspace where you want the symbol to be placed. Select a spot in the middle of the diagram workspace, and leave room to add entities above it. The entity symbol appears with the default name Entity_1 selected.
Note As long as you hold the left mouse button down, you can move the entity anywhere in the diagram you want.
2 Overwrite the default name with Guest and press Enter.
3 You should still be in draw mode: your cursor looks like a pen when you position it over the diagram workspace. Use the same procedure described in steps 1 and 2 to add another new entity, this one called Vehicle. Position it below Guest.
4 To turn off the drawing cursor, click the cursor arrow on the Draw toolbar or press Escape.
Reusing an Entity from the Project Encyclopedia
Reuse the Reservation entity, already established in the project encyclopedia.
1 Right click the diagram workspace and select Choices. You get a list of all existing definitions of types that can be drawn on this diagram. In this case, you get a list of all entities already defined in this project.
2 Drag Reservation onto the diagram workspace, to the right of Guest. Notice that the entity is drawn complete with all of its already-defined attributes.
Select and Drag dialog for Reservation
3 Also select Room from the Select and Drag dialog, and drag it onto the diagram workspace above Hotel Guest. Notice that it, too, is drawn complete with all of its already defined attributes.
4 Close the Select and Drag dialog.
Your diagram should look like the one below:
Define entities
Define attributes for Guest entity.
System Architect provides an underlying data dictionary of data elements and data structures that can be used in various definition types throughout the tool (entities, tables, UML classes, business processes, and so on).
A data element is an elemental piece of data. It can have a data type, and other properties. A data structure is a group of data elements. For example, you can have data elements such as Street Address, City, State, and Zip Code. You might combine all of these into a data structure called Address. In an entity, an attribute is considered an instance of a data element or a data structure.
To define attributes for the Guest entity
To open the Guest entity, select the symbol and choose Edit > Entity from the toolbar. This opens the Model Object - Entity dialog.
Note If you want the entity definition dialog to appear automatically each time you put an entity symbol on your diagram, from the Tools menu, select Preferences and check Auto > Define.
Using the Underlying Data Dictionary
First examine the data elements and data structures already defined in our underlying data dictionary for this project encyclopedia, to see if you want to reuse any for this entity.
1 Click Choices in the Attribute tab to open a list of all data elements and data structures already defined in the underlying data dictionary.
Note Creating Data Elements: System Architect allows you to define data elements and data structures before you use them in entities. In this way you establish an underlying data dictionary that you can continue to build on as you define data in or outside of entities.
To create a new data element or structure outside an entity:
In the Explorer Data Modeling tab, click Shared > Definitions > Data Element.
Or in the Explorer All Methods tab, expand the Definitions type, right‑click Data Element and select New.
2 Drag Guest_Number and Name into the Data column of the Attribute List grid (aim for the first cell). Two new attributes for this entity are created.
Defining an Entity dialog
3 By default, System Architect names the attributes Guest_Number and Name. You can change these names without affecting the names of the underlying data elements that the attributes report to.
4 Close the Select and Drag dialog.
5 Close the definition dialog box by clicking Cancel.
The attribute is considered the instance of the data element in this entity. It carries instance information, such as whether this data is a primary key for this entity, whether it is a foreign key, whether it can be null, etc. The data element carries that information which is globally true for all attributes based on this piece of data, such as the data type, qualifiers, default value, etc.
6 Click in the Name cell of Guest_Number to highlight the whole attribute name. Type over this name to change it to Guest#. Notice that the data element name (in the cell to its left) does not change.
7 The name of the column (in the physical model table) which is created from this attribute is the name of the data element with spaces and other special characters replaced by under-scores ( __ ). To modify this value, click Define under the grid. Click Cancel to close this dialog box.
8 Close the definition dialog box by clicking Cancel.
Specify primary keys
Specify Guest# as the primary key attribute:
The primary key of an entity is the attribute, or attributes, which uniquely identifies an instance of the record represented by the entity. By definition, therefore, the value of the primary key cannot be duplicated in the table in the database.
To specify Guest# as the primary key attribute
1 Toggle the PK cell next to Guest#.
2 Click in the cell for the attribute Guest# and then click Define at the bottom of the Attribute List box. You can open the full definition dialog for this attribute. Notice that in the Attribute Designation group, the property Primary Key is toggled. Click OK to close the dialog.
3 Click in the Guest_Number cell of the Data column and click Define again . You can open the full definition of the underlying data element. Notice that the properties and their values in this dialog are identical to those in the previous dialog for the instantiating attribute, except that this dialog does not contain the Attribute Designation group.
4 Close the data element dialog. Effects of Changes to Data Elements and Attributes: If you change any values in the data element dialog, they are applied globally across the data model: the values change for the data element, and all attributes that use the data element in all entities across the model. The same is true if you change a value in the attribute definition dialog: It will change the corresponding value in the underlying data element, and be applied globally across the model.
Add a data structure as an attribute
1 Click Choices in the Attributes List grid again.
2 Right click anywhere in the Select and Drag dialog and select Details.
3 Select the data structure Address. Notice that in the Details window, this data structure is shown to include the data elements Street, Town, and District. Drag it into the Data column of the Attributes List grid (aim for the next available cell). A new attribute for this entity is created.
Note Expanding Data Structures: At this point you could choose to expand this data structure into its constituent data elements in the Attribute List grid. You will not do it here. When you map this logical data model to a physical model, and this logical entity and its attributes are mapped to a table with columns, this data structure will be automatically decomposed into an equivalent column for each of its data elements.
If you do want to expand this data structure now, right-click Address in the Data column cell, and select Expand. After expanding, a column (titled Source Data Structure) in the Attribute List grid (located to the far right) names the data structure from which each element was expanded.
4 Click OK to close the entity definition dialog.
Create new data elements in an entity
Add new attributes to the Vehicle entity. This process also creates new data elements in our data dictionary.
1 Open the definition dialog for the Vehicle entity (double-click the symbol or right-click and select Edit).
2 On the Attributes tab, in the Attribute List grid, click in the first Data cell and enter the name for a new data element, Registration_Num and hit Return. Notice that in the grid, default values for the attribute's Data Type and Qualifiers are entered. The default value for Data Type is Character. The default value for Qualifiers is 10.
Note You cannot change the default data type and qualifier for data elements, attributes, and columns. But you can change the data type and qualifier whenever you want. It may be useful to create a logical model without paying any attention to these properties, and then during a review change them to more realistic values.
3 Toggle the PK cell for Registration_Num to make this the primary key for the Vehicle entity.
4 Enter another attribute called License_Plate_State and hit Return. Leave its default values for Data Type and Qualifiers. Toggle the PK cell for this attribute as well: you now have a two-part primary key for this entity.
5 Enter another attribute named Make, and hit Return. Again leave the default values for Data Type and Qualifiers.
6 Enter another attribute named Color and hit Return. Leave the default values for Data Type and Qualifiers.
7 Enter one more attribute, named Year, and hit Return. This time you can change the default values of Data Type and Qualifiers.
8 Click in the Data Type field so that a drop-down arrow appears. Click the arrow to display a list of available data types. Notice that these are generic ANSI data types; they are not DBMS-specific. That is because you are in a logical entity. When you map this diagram to a physical data model, System Architect maps generic data types to the data types for the specific DBMS you choose for the physical data model.
Entity dialogfor Vehicle
9 In the list of data types, select Integer.
10 Click in the Qualifiers cell for the Year attribute, and delete the default value of 10.
Note Column Name: As you work on this logical data model, System Architect is already preparing for mapping to a physical data model. Using the bottom scroll bar in the Attribute Grid, scroll to the right until you see the column called Column Name. Notice that the name of the data element is used as the column name for the table in the physical model you will eventually create. You can change the name of the column right here in the attribute grid.
You have some control over the way this mapping is done through the Dictionary > Options > Column Name Options dialog box.
11 Click OK to save the attributes in the entity definition.
Display options for an entity
System Architect provides you with a number of display options for the logical ER diagram:
1 Right-click the entity Guest and select Display Mode from the list. You are presented with a dialog that gives you a number of choices for display.
2 In the Display View group, select Key Based and click OK. Notice that only the primary and foreign keys are displayed on the entity symbols.
3 Right-click an entity (any entity) again and choose Display Mode. Change the display mode to Fully Attributed and click OK.
4 Select File > Save Diagram to save the diagram.
Lesson checkpoint
In this lesson, you learned how to:
draw entity symbols
define entities
specify primary keys
add a data structure as an attribute
create new data elements in an entity
display options for an entity