Database----Four Design patterns

Source: Internet
Author: User

Database----Four Design patterns

Design patterns are a set of reusable, most-known, categorized, code-design experience summaries.

Main expansion mode

Commonly used to extract common characteristics of different types of objects. Schools, for example, are divided into classes
Teachers and students, but for the canteen aunt or the doorman, see if you are in the school staff. This is an inclusive
Relationship. The school staff includes students, teachers and other staff. If you make a check-in system, set the school
The person is the user table, the teacher, the student and so on separate table, but all maintains the same userid simultaneously as both the main

Key. Make it a 1-to-1 relationship. This mode is the main expansion mode.

  The primary key of the extension table is both the primary key of the extension table and the foreign key of the primary table

Master-Slave mode

The master-slave mode has the most application scenarios. is a typical one-to-many relationship. such as the implementation of the bar, the whole
It's a master table. And there are many from the table is different from the landlord posts, and each post useful a lot from the table
That's the information for each building.

Name Value Relationships

The main processing system design phase has not yet fully determined the properties of the object. The properties of these objects are shipped in the system
There is a big change in the row, or there is a big difference between the properties of multiple objects.
A student's table, for example, records some of the attributes that a student must have: age, height, weight, or name. But suddenly there was
One day a person crosses, he needs a fencing value of data. An additional two tables are typically required to store this uncertainty whether
will use the properties that will be available.

First you need a property Template table , that is, regardless of who this attribute belongs to, what it is, when,
I just proved that there is such an extra attribute. In the example above, the attribute Template table is
You need to add an attribute: (attribute code is generally used for attribute classification)

ID 1 Property Code 1001 Property name Fencing value

But the specific fencing value is how much, this table is not discussed. The table that stores the data is called the extra attribute table , which
The fields stored by the table are identified separately
1. Which person or thing this data belongs to (role ID)
2. What is this data attribute (property template ID)
3. What is the specific value of the attribute (data)?

Many-to-many relationships

Many-to-many mode, is also a more common database design pattern, it describes the two objects are not divided into the main
Second, status equivalence, mutual one-to-many relationship. For a table, a record corresponds to multiple records of Table B, which is reversed
For the B table, a record also corresponds to a table of multiple records, this situation is "many-to-many mode."
This can be broken down into two main cases. Depending on the correlation table there is no business requirement.

Reprint: Common four kinds of database design patterns

Database----Four Design patterns

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.