A slightly different approach that we used was to create an abstract entity table. The goal was to provide a unique serial number for all specific objects. A simplified example is provided. 
--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 )
Our insertion methods are inserted into the BASE_ENTITY table and capture the received identifier value. Specific tables (employee, business_person) will store the received identifier as their PC. One of the main reasons for this is our business, marketing, that can force us to move entity tables as we learn more about them or reclassify people. We found that it simplifies the logic if object 478 is "the same" in the entire domain. Instead of making queries based on the type in your design, since the number is overridden in each table, the query simply joins the table, and if rows are returned, it's that type.
-- 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
Let me know if you have any design questions.
source share