SQL - many-to-many table primary key -
In this question comes after reading a comment in this question:
< P> When you create multiple-to-many tables, you should make a composite primary key on two foreign key columns, or create an auto-increment surrogate "ID" primary key, and just index it on your two FK columns. (And perhaps a unique obstacle)? What are the implications on performance for new records / re-indexing in each case?
In fact, it is:
PartVice ---------- PartID (PK / FK) DeviceID (PK / FK)
< / Pre>versus this:
PartVice ---------- ID (PK / Auto-Inchargement) Partaid (FK) Device ID (FK)
By creating two IDs, PK means that the order is physically sorted on the disk, so if we insert (Part 1 / Device1), (Part 1 / Device2), (Part 2 / Device3), then (Part 1 / Iwais 3) database table must have separate entries include last between 2 and 3. Many records, it becomes very problematic as it contains hundreds of thousands or millions of records added every time. On the contrary, an autoincrementing PK tries to eliminate new records.
The reason for this is that I want to always do the overall primary key, there is no rental auto-increment column, but I'm not sure the key to the key is actually More demonstrative.
With a simple two-column multiple-to-many mapping, I want to be a surrogate key No real profit is seen. Unique to keep a primary key on
(col1, col2)
, the values are honored (unique in theircol1
andcol2
referenced tables) and On a(col2, col1)
, different indexes will catch cases where the reverse order will execute faster. Instead of rent, space is a waste.You will not need an index on individual columns because the table should be used only to be included in two referenced tables.
That comment, you mention this question, it is not worth the electrons used in my opinion. It seems as if the author thinks that the table is stored in an array rather than a highly simplified multi-route tree structure.
For a start, is never required to store or retrieve on the table sorted, just index and index will not be archived , Will be stored in an efficient way to be able to recover it quickly.
In addition, the vast majority of database tables are often read away more than written. From this, anything you do on the selection side is more relevant than putting it.
Comments
Post a Comment