I've been designing a database for an online store system. The question that I've come across by reading some posts in this website is that although I can use composite primary keys in the case I'm gonna explain below, is it really a bad practice (according to the posts I read in this respect over stackoveflow, many says it is a bad practice so that's why I'm asking).
I want to store payments for the orders in a separate table. The reason is that, an order can have many items which are handled in a separate table in the form of many to many relationship. Now, if I don't use composite primary keys for my payment table, I'll lose my unique PaymentID
:
[PaymentId] INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
[OrderId] INT NOT NULL PRIMARY KEY --Also a Foreign Key--
Now, if I just remove the Primary Key for the OrderId
, I'll lose my one to one relationship here so Many OrderIds can be associated to many PaymentIds
, and I don't want this.
This is why the previously asked questions here have concluded (mostly) that the composite key is a bad idea. So I want to clarify this for myself; if it is bad, what's the best practice then?
See Question&Answers more detail:os