Reputation: 573
When designing a table for a many to many relations ship 1 sides primary key will come to the [M] side the middle table, my current middle table is
Salesline : Itemid(PK), SOId(PK), userid(PK)
or
Salesline : Itemid(PK), SOId(PK),
userid_salesorder(PK) , // links to the salesorder.userid attribute
userid_item(PK) // links to the item.userid attribute
Which is the correct way ?
Upvotes: 0
Views: 1655
Reputation: 6289
Looks like the natural realtionships between your entities are:
I would recommend to break the realtionship between the User and Item tables and to move the quantity of the particular item ordered to the SalesLine table. User, SalesOrder and Item should have simple, possibly surrogate, primary key. The primary key of the SalesLine may be composite, consisting of the foreign key to the SalesOreder table and, say, a line number within the order.
Upvotes: 1