What is the use of federated primary keys?

Source: Internet
Author: User

A federated primary key is a primary key that consists of 2 or more 2 fields. This combination is unique in the data table and has a primary key index, using the field contained in the primary key as the primary key.
It can be understood that, for example, your order table has a lot of fields, the general situation as long as there is an order number bill_no the master key can be, but now the requirements may be a complement
Filling orders, using the same order number, then the individual use of the order number is not possible, because there will be duplicates. Then you can use an order serial number BILL_SEQ.
As the difference. Set the Bill_no and Bill_seq as the Federated primary key. Even if the bill_no is the same, bill_seq can be different.

ALTER TABLE TABLE ADD constraint Pk_name primary key (column 1, column 2, ...)
The benefit of Federated primary keys is that you do not need to add a useless primary key column because you need a primary key for example, if you do not have a federated primary key, you must add a column ID to set the primary key, but this ID column
Without any effect as to when to use, just like the example, when you the table's primary key ID no use, then use the Federated primary key good, you can save
A column of space, but if the ID column of the table is to be a foreign key to another table, you cannot use the Federated primary key.

A federated primary key is the uniqueness of a record.

Like this time.
Product Brand product model
Nokia 920
Samsung NOTE2
Nokia 8088

For example, the product brand may be duplicated, are Nokia, but the Nokia manufacturer's product model is not duplicated
For example, many brands may have 920 of this model, but a brand has only a 920 model

So, by this joint key, you can determine the uniqueness of this record.

The establishment method is as follows
CREATE TABLE Product (
Pro_name varchar (20),
Pro_type varchar (20),
Primary KEY (Pro_name,pro_type)




The answer to Baidu search

What is the use of the

Federated primary key?

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.