I’m designing a document management system for a school (SQL & .NET). The school has various data it would like to store, such as personnel, pupils, financials etc. The system should be able to attach a document to any of the records in the system irrespective of its type (personnel, pupil…)
A typical ER way of doing this would be to create tye different type tables (personnel…) as well as a Documents table. To associate the type table records to the document records, one would need a “link table” such as PersonnelDocuments, with the columns PersonnelID and DocumentID.
I find this approach to be a bit clunky as there might be 100s of type tables (in future systems) who would each need a linking table. Is there a more generic way of doing it, while still following proper ER DB design.
One solution is to make your unique identifier so big that that every object in the database has a unique identifier regardless of the table it is in (GUID is often just that). Once you have a unique identifier for every object, you only need a single link table. I have used this approach for an application which required you to be able to post comments on any object in the database, and just as you did, I found that dozens of tables named XXXXComments and YYYYComments just was not going to cut it. This solution cleaned things up nicely.
EDIT:
Yet another approach I have used in the past is to make all the tables that require a documents link derive from the same base table. This approach is often quite clunky in itself however unless your domain is rather small, or the section requiring the documents link is self contained. If I remember correctly, I was creating a reports tracking application in which all there were many types of reports, each of which could be forwarded to different groups in the company, then were returned and forwarded to other groups until all necessary items were acquired for processing. I ended up creating a report base table and my link table for forwards used that Id instead of creating a forwards table for each type of report.