Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A slightly different approach we used was to create a abstract entity table. It's purpose was to provide a unique sequence number to all the concrete entities. A simplified example follows <img src="https://i.stack.imgur.com/Gddh3.png" alt="entity structure"></p> <pre><code>--CREATE SCHEMA user893847 CREATE TABLE user893847.BASE_ENTITY ( entity_id int identity(1,1) NOT NULL PRIMARY KEY ) CREATE TABLE user893847.EMPLOYEE ( entity_id int NOT NULL PRIMARY KEY , name_first varchar(30) NOT NULL , name_last varchar(30) NOT NULL ) CREATE TABLE user893847.BUSINESS_PERSON ( entity_id int NOT NULL PRIMARY KEY , company_name varchar(30) NOT NULL ) CREATE TABLE user893847.ADDRESS ( entity_id int NOT NULL , address_line1 varchar(70) NOT NULL ) </code></pre> <p>Our insert methods would make inserts into the BASE_ENTITY table and capture the resulting id value. The concrete tables (employee, business_person) would store the resulting id as their PK. One of the main reasons for this was our business, marketing, could have us moving entity tables as we learn more about them or reclassify an individual. We found it simplified the logic if entity 478 is the "same" throughout the domain. Rather than having to do queries based on type in your design, because a number is redefined in each table, you query simply joins to the table and if rows come back, it <em>is</em> that type.</p> <pre><code>-- your query SELECT C.* , E.* -- build out a null set of colums for business men , NULL AS id , NULL AS business_type FROM Clients C INNER JOIN Employees E ON E.id = C.reference_id WHERE C.type = 'employees' UNION ALL SELECT C.* -- repeat the build out for faking the employee columns , NULL AS id , NULL AS name , ... , BM.* FROM Clients C INNER JOIN business_men BM ON BM.id = C.reference_id WHERE C.type = 'employees' -- my aproach SELECT C.* , E.* -- build out a null set of colums for business men , NULL AS id , NULL AS business_type , ... FROM Clients C INNER JOIN Employees E ON E.id = C.reference_id UNION ALL SELECT C.* -- repeat the build out for faking the employee columns , NULL AS id , NULL AS name , ... , BM.* FROM Clients C INNER JOIN business_men BM ON BM.id = C.reference_id </code></pre> <p>Let me know if you have questions about the design</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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