Q: MySQL composite primary key index and (unique) composite index problem?

Source: Internet
Author: User
This is a user table associated with the Group table uid,group_id is the only pair.

"Scenario 1: (unique) composite Index"
UNIQUE KEY uid_group_id (uid,group_id)

"Scenario 2: Composite primary Key"
PRIMARY KEY (uid,group_id)

1: I hope the great God can combine this example to explain which kind of scheme is better, and similarities and differences.

2: The first way specific name how to call Ah, still do not know?

Thanks, ^_^.

Reply content:

This is a user table associated with the Group table uid,group_id is the only pair.

"Scenario 1: (unique) composite Index"
UNIQUE KEY uid_group_id (uid,group_id)

"Scenario 2: Composite primary Key"
PRIMARY KEY (uid,group_id)

1: I hope the great God can combine this example to explain which kind of scheme is better, and similarities and differences.

2: The first way specific name how to call Ah, still do not know?

Thanks, ^_^.

If the two fields are incremented, use the primary key to conform to the index, and if not all increment it with a unique one.
But in fact, no matter how the table structure design is very strange.
Call it random, I think the only compound index on the line, as long as others understand it.

  • 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.