Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Mastering UML with Rational Rose 2002.pdf
Скачиваний:
137
Добавлен:
02.05.2014
Размер:
9.68 Mб
Скачать

Chapter 18: Rose Data Modeler

Enter a default value, or select a value from the list box if fields that use this domain should have a default.

On the Check Constraints tab of the specification window, you can set constraints for the domain. A constraint is an expression that must be true before data can be altered in the database. For example, you may want to enforce a business rule that requires all transactions in an accounting system to have a transaction number greater than 1000. You can create a domain called Transaction, and add a constraint that checks the value of the field and returns False if the value is less than 1000.

Constraints can also be added to individual tables; we will discuss this in the next section, "Adding Tables." A domain constraint appears in the browser below the domain, and has the stereotype <<Check>>.

On the Check Constraints tab, select New to add a new constraint. Rose will automatically create a constraint name for you and populate the Name field. In the Expression field, enter the SQL statement for the constraint. To edit an existing constraint, select the constraint from the drop−down list box in the Name field.

You can drag and drop a domain onto a Data Model diagram. Rose will use the following symbols if the stereotype display is set to Decoration or Icon, respectively.

Adding Tables

Once you have established a schema, you can create tables in it. Each table in a database is modeled as a persistent class in Rose with a stereotype of Table. The tables within a schema must have unique names. In Rose, a table is modeled using the following symbols, when the stereotype display option is set to Decoration or Icon, respectively:

626

Chapter 18: Rose Data Modeler

The DBMS for the table is set by the DBMS of the schema containing it. In other words, all tables within a schema use the same DBMS.

To add a table:

1.

Open a Data Model diagram.

2.

Select the Table button from the toolbar.

3.

Click anywhere inside the diagram to create the table.

4.

Type the name of the new table.

OR

1.

Right−click the schema in the Logical view.

2.

627

Chapter 18: Rose Data Modeler

Select Data Modeler → New → Table.

3.

Type the name of the new table.

The next step in the process is to add details to the tables: fields, keys, indexes, constraints, and triggers.

Adding Columns

Each field, or column, in the database is modeled as an attribute in the Logical view under the table that contains it.

There are two types of columns: data columns and computed columns. A computed column uses a SQL statement to calculate its value from one or more other columns. For example, a company might have a retirement fund set up, and each employee is able to place a maximum of 4 percent of their annual salary into this fund. The table Employee would include the two columns: AnnualSalary and MaxRetirementContribution. The value in MaxRetirementContribution would be equal to 4 percent of the value in AnnualSalary. MaxRetirementContribution, therefore, is a computed column. A data column is any column that does not contain a calculated value.

Microsoft SQL Server also supports the concept of an identity column, which is a column with a system−generated value. For example, an identity column with a data type of Integer would assign the values 1, 2, 3, 4, and so on to the rows in the table.

To add a column:

1.

Right−click the table and select Open Specification.

2.

Select the Columns tab of the specification window.

3.

Right−click anywhere in the white space and select Insert.

4.

Double−click the new column. This will open the Column Specification window.

5.

628

Chapter 18: Rose Data Modeler

Enter the name of the new column.

6.

Select the Type tab:

7.

Select the Data Column or Computed Column radio button (SQL Server only).

8.

If the column is a data column, enter the following:

Domain, if you have created a domain and wish to apply it to this column. If you use a domain, you will not need to enter any of the following fields other than Unique Constraint or Primary Key. The domain definition will cause the other fields to be automatically filled in for you.

Data Type for the column. The choices available in this drop−down list box will depend on the DBMS for this table.

Length, which is the number of characters allowed in the column. This value cannot be set for all data types.

629

Chapter 18: Rose Data Modeler

Precision, which is the number of digits allowed in a numeric column. This value cannot be set for all data types.

Scale, which is the number of digits to the right of the decimal point in a numeric column. This value cannot be set for all data types.

Unique Constraint, if the values in the column must be unique.

Primary Key, if this is the identifying column for the table. You can create a composite primary key by selecting this option for more than one column. When a column is a primary key, it has a red "PK" to the left of it in the browser.

Not Null, if the column will not allow null values. If you set the Primary Key option, the Not Null option must also be set.

Identity (SQL Server only), if this is an identity column. SQL Server will automatically generate values for an identity column. Note that the data type must be a numeric type to allow this option.

For Bit Data (DB2 only), if the column supports ForBitData.

9.

If the column is a computed column (SQL Server only), enter the SQL statement that will be used to calculate the column value.

10.

Select the Check Constraints tab and add constraints if necessary. See the upcoming section, "Adding Constraints."

OR

1.

Right−click the table in the Logical view.

2.

Select Data Modeler → New → Column.

3.

Type the name of the new column.

4.

Double−click the new column to open the Column Specification window. Complete the column specifications as described above.

630