mysql - Design considerations to using Foreign Key as Primary Key -


Any common design idea (good / bad / neutral to use foreign key as a primary key for a table )? Another table?

For example, consider the following tables as part of a movie catalog:

  titles ------ id episode ------- - The episode can be clearly done with both an ID and a title_id, where the id PK and title_id will be unique, but because title_id is already unique, and technically, the episode recognizes, whether the form of PK Will it have anything to use in this? What about general?   

Your question is basically a description of the technique known as "shared primary key" Accordingly, I have changed two tags about primary key and foreign key with a tag sharing primary key.

The shared primary key is a design where PK of a table is also an FK that references the PK of another table. Since the tag wiki indicates a shared primary key, it is useful for one-to-one relations, whether they are compulsory or optional. These relationships are sometimes called IS-A relationships, as "the relationship between vehicles and auto" is also known as class / subclass or type / subtype relationship. " p> Like any design technique, its benefits and its costs are

Edit in response to comments:

The biggest advantage of sharing the primary key is that this relationship Applies 1-to-1 nature. This rule in the database is generally more productive than trying to ensure that all application codes follow the rule.

A secondary advantage is that connecting between two tables is simple and fast. It is fast (for some database systems) to accelerate connectivity due to the index created for PK support.

One-third of the benefits is that one-third table can refer to both of these two tables with the same FK.

The cost is that in order to add a new entry to some tables, some programming is included, from the primary table, the PK must be copied into the secondary table, and the system will not usually do it for you. Also, at the time of joining, it is not free.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -