编辑推荐: |
本文描述了 IBM® Rational® Software Architect
for WebSphere® Software、IBM® Rational® Software
Architect Standard Edition,以及 IBM® Rational®
Software Modeler 对序列图编辑器的改进,这些改进使得修改图表变得更加容易,本文逐步地指导您使用这些较新产品增强的建模功能来移植
UML 模型 本文来自IBM,由火龙果软件Alice编辑,推荐。 |
|
首先感谢好友陈海华的帮助,在我都要忘记这些步骤的时候给我提示,写这样一个教程,既是给自己一个参考,同时希望也能给大家带来一些方便。
这里以MS SQL Server2000中已有的一个Northwind库为例,我们命名新的数据库名为NorthwindRose;我们只挑其中的两个表Customers和Employees做示例,另外我们再新建一个Card表,来建立表间关系,其他依此类推;前提当然是你已经安装了Rose
2003和 SQL Server2000,OK,我们开始
注:对文章中提到的一些概念,如模式、表空间,请参考书《UML数据库设计应用》,人民邮电出版社出版
先看最终效果

图一、SQLServer2000中的关系图

图二、Rose2003中的关系图
第一步:在Rose2003中新建一个MDL文档,命名为Northwind.mdl
第二步:展开Componet View,New一个DataBase,命名为NorthwindRose,这就是会出现在SQLServer中的新库名,这里可以注意到,Rose自动在“Logical
View”中新建了两个包“Global Data Types”以及“Schemas”

图三、新建DataBase
第三步:右键选中“NorthwindRose”,打开“Open Specification”,选择Target为“Micfosoft
SQL Server2000.x”,如果要导入到别的类型的数据库,同样可以选择,目前我还没有试过,欢迎大家写其他各种版本的参考手册

图四、选择目标数据库类型
第四步:新建NorthwindRose的表空间,右键打开“NorthwindRose”-“Data Modeler”-“New”-“Tablespace”,一般情况下,请把表空间命名成“PRIMARY”,例子里我将表空间命名为NorthwindSpace,这里待会还要重点讲一下,因为导入SQLServer2000的时候可不是随便什么表空间名都可以的,必须与SQLServer中的“文件组”中的项目相对应。

图五、新建表空间
第五步:右键选中“Logical View”中的“Schemas”,新建一个Schema,我这里命名为Schema_Actor,大家可以随意命名,自己理解就行;

图六、建立一个模式
第六步:右键打开“Schema Actor”,新建一个Data Model Diagram,取名为Main,双击这个Main图标,我们可以看到工具栏的变化,如下图

图七、建立数据模型视图,并双击打开,出现新的Toolbar
第七步:右键打开"Schema_Actor"的“Open Specification”,将DataBase选择为"NorthwindRose",表明从属关系,同时新建一个Table,

图八、在模式下新建表格
第八步:在模式“Schema_Actor”下新建三个表Card、Customers和Employees,这里我以建立Card表为例,介绍怎么在Rose2003中建立表格,以及如何设置主键、选择数据类型以及数据长度等

1、将工具栏的“Table”拖放入Main数据视图,出现T_5表格
2、双击T_5表格,设置表格参数将Name设置为Card,选择Tablespace为NotrhwindSpace

3、选择“Columns”,右键空白区域选择“Insert”插入新列
4、编辑新建的列属性,将Name设置为CardID,注释为卡的ID,主键

5、选择“Type”设置CardID的数据类型和长度,并设置成主键
6、同样建立一个名为CardType的列设置数据类型为nvarchar,长度为10
第九步:模仿第八步提到的方法,建立Customers表和Employees表,并使用Toolbar中的Identifying
Relationship和Non-identifying Relationship两个工具建立三个表之间的关系,Identifying
Relationship表示主外键关系,拖动方向应该是从父表指向子表,下图中的Card表为父表,Customers和Employees表为子表,CardID为其他两个表的主键和外键;Non-identifying
Relationship则仅仅是建立外键关系

注意:先选中工具,然后选择Parent表,拖动连线指向子表即可
图十二:建好后的表关系图
建立好表关系之后,就可以导入数据库了,请按照以下步骤进行操作
第十步:打开SQLServer的“企业管理器”,新建一个名为“NorthwindRose”的数据库,与Rose中的DB同名,打开属性,在“文件组”一栏加上“NorthwindSpace”,这里就是对应Rose中的Tablespace

图十三、Tablespace和文件组的关系
第十一步:右键打开“NorthwindRose”,并选择“Forward Engineer”,点击“下一步”,选择想导入的部分,再“下一步”,选择“Execute”,填入SQLServer的登陆帐号密码,选择刚才建立的“NorthwindRose”数据库,选择下一步导入

图十四、导入过程
检查一下SQLServer2000,应该可以看到表都已经自动建立好了,如果导入不成功,基本上是以下几个原因:
1、 在建立表的时候,没有选择相应的Tablespace
2、 Rose中的Tablespace在SQLServer2000中的文件组中找不到对应项

图十五、导入后的表结构
到这里,貌似一切都很顺利应该成功了,我们试着在Card表里添加一条数据看看,会出现如下错误提示:

图十六、新建数据时候的错误
可以看出,我们自己命名的“NorthwindSpace”的表空间是有问题的,这时候我们还是把Rose2003的Tablespace改为“PRIMARY”;重新导入,再试试看。重新导入之前,要先把NorthwindRose库里的表先删除。最后可以看到一个可以使用的库了
好的,下次我再写写Rose2003和SQLServer的数据视图、存储过程导入以及如何保持两者同步
|