Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to transform an class diagram to an relational database diagram? [closed]

I have created an class diagram of my application, I wonder if it's possible to create an relational database diagram based on the class diagram. If it's possible, can it also be done the other way arround?

like image 600
onepseudoxy Avatar asked Mar 04 '11 22:03

onepseudoxy


People also ask

How do you convert class diagram to ERD?

Convert ER diagram to Class diagramSelect [Convert to Class Diagram] from ER Diagram's pop-up menu in the structure tree. The diagram and all the model elements inside will be converted to a Class diagram and appears in the tree view.

How is a class on a class diagram represented in a relational database?

In building a relational database, each class is first translated (mapped) into a relational model scheme. The scheme is identified by the plural form of the class name, and lists all of the attributes in the class diagram.

What is the difference between ERD and class diagram?

Class diagrams and ERDs both model the structure of a system. Class diagrams represent the dynamic aspects of a system: both the structural and behavioural features. ERDs, depicting only structural features provide a static view of the system.

Is a class diagram a database diagram?

The main difference between Class Diagram and Entity Relationship Diagram is that Class Diagram represents the classes and the associations among them in a software program while an Entity Relationship Diagram represents the entities and their relationships between them in a database.


2 Answers

A class diagram represents a system using the object model. A relational database diagram represents a system of data using the relational model. There are significant differences between the ways these two models will present the same system. And a data model does not model behavior. It only models data.

There is, however, a modeling system that is sort of halfway between a class diagram and a relational diagram. Its called an E-R diagram, where E-R is short for Entity-Relationship. In the E-R model, the entire subject matter is analyzed into "entities", which can be persons, places, or things that have an identity. They can even be intangible things, like a bank account. Relationships involve two or more entities, and its assertions about the relationships that make up much of the data in a database. Data values are instances of attributes, and attributes describe either entities or relationships among entities.

Most of the E-R diagrams you'll see in SO are really relational diagrams masquerading as ER diagrams. In a true ER diagram, foreign keys are not present, many-to-many relationships can be diagrammed as a single line, and such things as gen-spec patterns look much the same way as they do in class diagrams. If fact, an ER diagram can be viewed as the projection of an object world onto the world of data only.

If you'll learn ER modeling as a distinct activity from relational modeling, resulting in a different model, you'll find it fairly easy to transform class diagrams into ER diagrams.

From there, transforming ER diagrams into relational diagrams is almost mechanical. Every entity gets a table, many-to-many relationships get their own table. Inheritance and association get special treatment, and so on. Relationships which were treated as abstractions in the world of ER modeling become materialized as foreign keys. The primary key of each table becomes obvious in terms of the key attributes of entities in the ER model.

And what were called "attributes" in the ER model (possibly "properties" in the class model) become "columns" in the relational model.

there are some fancy tools that manage object models, ER models, and relational models all in the same tool, and can move between these models for you. One of them, "Data Architect" was very good but very pricey a few years back.

like image 85
Walter Mitty Avatar answered Oct 19 '22 22:10

Walter Mitty


Not sure what you mean by a "relational database diagram". If you refer to a SQL script with the DDL sentences to create the relational schema for your model, then maybe you can just see how tools do this transformation (e.g. check this online UML to SQL code generator http://modeling-languages.com/content/uml2db-full-code-generation-sql-scripts-databases)

Most of the transformations rules are straightforward (class-> table, attribute ->column, association -> foreign key,...) but you can play with UML diagrams with inheritance and association classes and see how this is translated.

like image 22
Jordi Cabot Avatar answered Oct 19 '22 22:10

Jordi Cabot