Logical view

advertisement
92.3913
March 2005
Creating a database from your class model - example
Logical view
Create your class diagram with Program, Course, Offering with
 a many-to-many association between Program and Course, and
 a one-to-many association between Course and Offering.
Classes that will persist must have the persistence property set on (on the Detail tab).
Component view
Right-click and select Data Modeler, select New, select Database, name your database.
Double-click your database and choose a database target type such as Microsoft SQL
Server
Logical view
Right-click the Schemas Package and select Data Modeler, select New, select Schema.
The default name of your schema will be S_0; rename it to MySchema
Logical view
Right-click and create a new package – name it MyClasses.
Right-click a class and drag it to your package MyClasses. Repeat for the other classes.
Right-click MyClasses and select Data Modeler, select Transform to Data Model, choose
your database schema MySchema and then your target database MyDatabase, and click
OK. MySchema is now filled with four tables named using prefix T_
Table
T_n
T_Course
T_Offering
T_Program
Comments
Generated by Rational Rose due to the many-to-many association between Program
and Course.
PK comprises two attributes that are FKs (referencing T_Course and T_Program).
Generated by Rational Rose for the Course class.
Rose generates four attributes:
 a PK, T_Course_ID.
 three other attributes that were defined in the Course class.
Rose generates an identifying relationship to the T_n table (identifying means that
the PK of T_Course appears as part of the PK of T_n.
Rose generates a non-identifying relationship to the T_Offering table (nonidentifying means that the PK of T_Course appears as a FK in T_Offering.
Generated by Rational Rose for the Offering class.
Note that Rose generates four attributes:
 a PK, T_Offering_ID;
 a FK, T_Course_ID that references the T_Course table;
 two other attributes that were defined in the Offering class.
Generated by Rational Rose for the Program class.
Rose generates a PK, T_Program_ID.
Rose generates two other attributes that were defined in the Offering class.
Rose generates an identifying relationship to the T_n table (identifying means that
the PK of T_Program appears as part of the PK of T_n.
92.3913
March 2005
Right-click your schema MySchema and select Data Modeler, select Forward Engineer
and the dialogue enables you to create a DDL file that contains a script that can be run in
the target database to create the relational database:
CREATE TABLE T_Course (
title SMALLINT NOT NULL,
description SMALLINT NOT NULL,
creditHours SMALLINT NOT NULL,
T_Course_ID INT IDENTITY NOT NULL,
CONSTRAINT PK_T_Course4 PRIMARY KEY NONCLUSTERED (T_Course_ID)
)
GO
CREATE TABLE T_1 (
T_Program_ID INT NOT NULL,
T_Course_ID INT NOT NULL,
CONSTRAINT PK_T_17 PRIMARY KEY NONCLUSTERED (T_Program_ID, T_Course_ID)
)
GO
CREATE TABLE T_Program (
name SMALLINT NOT NULL,
desription SMALLINT NOT NULL,
T_Program_ID INT IDENTITY NOT NULL,
CONSTRAINT PK_T_Program6 PRIMARY KEY NONCLUSTERED (T_Program_ID)
)
GO
CREATE TABLE T_Offering (
slot SMALLINT NOT NULL,
room SMALLINT NOT NULL,
T_Offering_ID INT IDENTITY NOT NULL,
T_Course_ID INT NOT NULL,
CONSTRAINT PK_T_Offering5 PRIMARY KEY NONCLUSTERED (T_Offering_ID)
)
GO
CREATE INDEX TC_T_112 ON T_1 (T_Program_ID)
GO
CREATE INDEX TC_T_113 ON T_1 (T_Course_ID)
GO
CREATE INDEX TC_T_Offering11 ON T_Offering (T_Course_ID)
GO
ALTER TABLE T_1 ADD CONSTRAINT FK_T_14 FOREIGN KEY (T_Program_ID) REFERENCES
T_Program (T_Program_ID)
GO
ALTER TABLE T_1 ADD CONSTRAINT FK_T_15 FOREIGN KEY (T_Course_ID) REFERENCES
T_Course (T_Course_ID)
GO
ALTER TABLE T_Offering ADD CONSTRAINT FK_T_Offering3 FOREIGN KEY (T_Course_ID)
REFERENCES T_Course (T_Course_ID)
GO
Download