The data model describes the logical content and structure of the system persistence database layer, and the data model is described by UML class diagram. First, it briefly introduces the design method of data model and several terms of relational database, then describes how to map classes to tables, map associations to relational databases, and map generalizations to databases.
The database model can be divided into 3 categories: the conceptual data model, the logical data model and the physical data model.
The conceptual data model is a user-oriented, real-world data model, which has nothing to do with the database management system, the logical data model reflects the DBMS storage structure, the data model that the user sees from the database, the physical data model is a specific DBMS, and defines how the actual data is stored on the persistent storage device The data model to be designed in this chapter is the logical data model, and it is not very different to design the data model with the Object-oriented method in the traditional method.
The design steps are:
1, design the entity in UML and the entity in ER diagram
2. Design UML entity class Diagram and E-R diagram
3, Modeling basis
4. Select Database System
The persistence database layer can be a relational database or an object-relational database or an object database. From relational database technology to object database technology is an evolutionary process, object database technology is the intermediate stage of this evolution process, although the future will belong to the object database, but the relational database in the current database software market still occupy the mainstream, this chapter for system Instance select relational database as the holding The database management system of the database layer of the long nature. For relational databases, you can use class diagrams to describe database schemas, use classes to describe data tables, and describe triggers and stored procedures with the operations of classes.
1, mapping the class to the table
To map an entity class to a relational data table, you must follow the first normal form of the table. A column must be a data item that cannot be divided, and a mapping from class to table can be one-to-one, that is, a class is mapped to a table, but one-to-one mapping can cause problems such as too many tables, missing tables, and unreasonable generalization relationships, etc. The design should be flexible adjustment.
2. Mapping relationships to relational databases
The multiplicity of classes can be divided into one-to-one, one-to-many and Many-to-many 3 cases, the processing of 3 kinds of multiplicity has some general conversion rules, the design of the data model with UML symbol stereotypes and other extension of the class simulation, relational table of the UML notation for the structure of "relational table" The class symbol representation, the column of the relational table is represented by the attribute in the class, the attribute with the constructor "PK" represents the primary key, the property with the stereotype "FK" represents a foreign key, and the column that cannot accept the null value is represented by the constraint "{NOT NULL}" class.
3. Map generalization to Database
There are 3 ways to map generalizations to a database: 1. Map each class to a table, create an SQL view for each parent class/subclass; 2. Maps an entire class hierarchy to a parent class table that includes the set of attributes for all classes; 3. Maps each subclass to a table, and all properties of the parent class are contained in the column set of each table.
Note: The dependencies and implementation relationships in the object-oriented design model are unstructured relationships and are not mapped to relational databases.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/project/