Note that there are some explanatory texts on larger screens.

plurals
  1. PODatabase modeling for a weak entity
    primarykey
    data
    text
    <p>I have 2 tables in my database <code>orders</code> and <code>orderHistory</code>. </p> <pre><code> ----------------- ----------------------- | orders | | orderHistory | ----------------- ----------------------- | orderID (PK) | | historyLineID (PK) | | orderDate | | status | | price | | quantity | ----------------- ----------------------- </code></pre> <p>Now an <code>order</code> can have multiple <code>history lines</code>. However, a <code>history line</code> can't exist on its own. I heard this is called a weak entity and therefore the <strong>PK</strong> from <code>orders</code> must be part of the <strong>PK</strong> of table <code>orderHistory</code>.</p> <p><strong>Questions</strong></p> <ol> <li>Is this really a correct <em>weak entity</em> relationship? Is there other ways to identify them?</li> <li>Should I add the <strong>PK</strong> of table <code>order</code> to table <code>orderHistory</code> and make it a composite primary key?</li> <li>In case I decide to add a new record to <code>orderHistory</code>, how will I add a new composite key? (<code>orderID</code> is available from table <code>orders</code>, but <code>historyLineID</code> should be auto incremented.) </li> <li>What if I decide to model this as a normal <strong>One-To-Many</strong> relationship where <code>orderID</code> is added as a foreign key <strong>only</strong> instead? what are the cons of doing so?</li> <li>Will ignoring Weak entities at all cause any problems later in a design provided all tables are in 3rd normal form?</li> </ol> <p><strong>Note</strong></p> <p>Both <code>orderID</code> &amp; <code>historyLineID</code> are surrogate keys. Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload