Use PD to design multiple-to-multiple intermediate tables.

Source: Internet
Author: User

Design multiple-to-multiple tables to solve repeated problems

Currently, there are two popular design methods: one is to create a separate id Primary Key in the intermediate table, and the key associated with the business table is set to unique; the other is to join the primary key, in this way, the intermediate table does not have a primary key unrelated to the business table, that is, the keys associated with the business table are combined as the primary key.

The following are two detailed methods to design tables using PD:

Method 1: The intermediate table uses a separate id Primary Key, which is irrelevant to the business table.

Double-click the table model and select Keys to add the unique primary key name you want to set.

Double-click the arrow in front of the red box and select the unique key for MySQL check.

Then select columns to add the column to be unique

Click "OK". The table is shown below.

 

Method 2: The traditional primary key combination method is also my favorite method. This method is simple, you only need to check the primary keys of fields in the design table, do not include a primary key unrelated to the business, that is, the primary key is composed of the key Union of the business table and is unique.

It's that simple. Click OK.

 

Summary: each of the two methods has its own advantages and aims to ensure the uniqueness of the Data. method 1 is easy to maintain, but the disadvantage is that the steps are slightly complicated and redundant business-independent fields are required; method 2: simple operations do not need to contain business-independent fields, which is not easy to maintain.

 

Use PD to design multiple-to-multiple intermediate tables.

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.