Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 Multiple Tables, Foreign Key problems

Author  Topic 

okkercat
Starting Member

3 Posts

Posted - 2009-07-29 : 19:13:47
Hello,

I am working on an open source project where I am trying to implement a sort of mapping system. The idea is to have a location table with all the relevant mapping data and then a foreign key to the mapped entity. It seems pretty straightforward until you realize that there are multiple entities that can be located. Like: Houses, People, Businesses, etc... all with their own tables and own primary keys. My problem is that I want to have just one location table instead of a bunch of different tables named people_location, business_location, etc... , but I don't know how to do that. Since it's an open source project, I don't have the clout to change the data model and make all entity tables 'extend' a single searchable_entity table, which would be ideal. All I can do is add on to the data model. Any ideas?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-07-29 : 19:20:54
Just add a LocationType column to your new table so that you know which row corresponds to which table. For instance, value of 1 could mean it's a business.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

okkercat
Starting Member

3 Posts

Posted - 2009-07-29 : 19:33:58
Thanks. I should have known that.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-07-30 : 12:44:05
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -