Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Resources to entity tables relationship

$
0
0
Hello,I have about 100 tables which represents different entities related to person. For example, tables are person_car, person_children, person_house etc. So, in person_children are stored info about all children with data like first name, last name, birth date etc., in person_car is list of cars etc.On the other side, I have table person_document, where documents are stored in binary field. Basically, user upload picture (scan) or PDF and code stores it in database in binary field.Each document should be related to one row in one entity table. For example, scan of driving license is stored in person_document as binary, and that row should be somehow related to one row in person_driving_license table (person_driving_license has fields like license_date, jurisdiction, expiration_date etc.).[b]One row in document table belongs to one row in one entity table[/b], but [b]row in entity table could have multiple documents[/b] (e.g. current license scan and keep all previous scans as history).Does anyone has idea how I could relate records from person_document to rows in each entity table?I thought maybe to add entity_id in person_document, but how to define table name? Add one more field table_name in person_document? That sounds like I would need dynamic SQL then, to read table name and build query (can't have table name as variable in query).Or, one more idea, to add new document_group table with only one field doc_group_id. Then add same doc_group_id field in person_document, and also in entity tables. So relationship could be:entity_table.doc_group_id -> document_group.doc_group_id -> person_document.doc_group_idAdvantage on this way is that I would avoid defining of table name in fields, so query is simpler. Please advice, did anyone work on similar case? How this problem is commonly resolved? Thanks!

Viewing all articles
Browse latest Browse all 3145

Trending Articles