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
 Is this set of tables a good approach?

Author  Topic 

koto
Starting Member

6 Posts

Posted - 2011-03-06 : 16:52:24
Hello,

I've following tables setup:

Address (ID, Street, Town...)
Person (ID, AddressID (FK to Address table) FirstName, LastName...)
Customer (ID, PersonID (FK to Person table), Vip ...

Customer's address data would be then obtained by view joining these tables.
Is this a good approach from the 'performance/convinience of use' point of view ?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-03-06 : 17:08:26
I don't see any reason to split off address into its own table. I think I'd just leave that info in the Person table.

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

Subscribe to my blog
Go to Top of Page

koto
Starting Member

6 Posts

Posted - 2011-03-07 : 04:10:58
Hello Tara

Thank you for the answer. The system is quite large and there are other tables using address:

Company (ID, AddressID, Name...)
Driver (ID, AddressID, LicenceType...)

So having address data in the separate table has some advantages.
Would you add address fields also to these tables?

I have a strong background in OO programming and there you always try to avoid fields repetition.
I know that Db is a different thing, so I'm wondering how db experts would approach this.
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2011-03-07 : 04:45:18
quote:
I know that Db is a different thing, so I'm wondering how db experts would approach this.
Well...Tara is an expert and she has stated her opinion.

But I'd say it depends on what kind of logic you are thinking of here. If for example you register a company with an address and you also register all its employees with the same address then it makes sense to store it in a separate table to avoid duplication. But if you want to register two neighbors that have just a different house number it will be far better to store the address twice as columns in the person-table.

- Lumbago
My blog-> http://thefirstsql.com/2011/02/07/regular-expressions-advanced-string-matching-and-new-split-function-sql-server-2008-r2/
Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2011-03-07 : 05:31:37
u need to have seperate table for address because one person may have multiple address.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-03-07 : 13:22:11
I am certainly not an expert.

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

Subscribe to my blog
Go to Top of Page

mmarovic
Aged Yak Warrior

518 Posts

Posted - 2011-03-08 : 15:15:15
quote:
u need to have seperate table for address because one person may have multiple address.
One person might have multiple address, but model assumes that it will store just one. Separate address table makes sense in case there are multiple persons with the same address.

Mirko

My blog: http://mirko-marovic-eng.blogspot.com/
Go to Top of Page

koto
Starting Member

6 Posts

Posted - 2011-03-08 : 16:57:18
Hi

To sum it up, the best solution from performance point of view
would be to resign from address table and have its fields repeated in Person and Company tables?
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-03-08 : 17:33:53
That depends on how much space the address data would take for each row in each table, and how many queries you'd perform that don't require that address data. If you always have to retrieve address data, then it's probably better to keep it in the same table. But if you only need it 20-30% of the time, and the address takes up more than 30% of the space in a row, you'd likely get better performance by splitting them into separate tables. Reducing the amount of data in-row increases the number of rows you can store in a page, reducing the number of pages needed in memory, and in turn reduces the amount of disk I/O.

If you really want to find the best design you'll need to test different scenarios. If you have to settle on a specific object model, use views or stored procedures to return data to your object layer in a consistent format. You can then test different table structures and interface with their appropriate view/stored procedure.

There are somewhat larger concerns that you should also consider:

1. Can a Person, Customer, etc. ever change their address? Does their address history need to be preserved? (if true, none of the suggested designs will accomplish this)

2. If a Person, Customer, etc. (multiple object types) have the same address, is there a solid business case to keep the address separate for each? Example: if 5000 Persons work at a Customer, and they all have the same address as the Customer, is it required to save the same address data 5001 times? Or just 5000 times? (This is a tremendous waste of space, and will definitely hurt performance)

3. As mentioned earlier, can Persons, Customers, etc. have multiple addresses? Not just address history, but different addresses like billing, shipping, home vs. business, and so on?

If your current requirements haven't considered these scenarios, you may have significant problems in the future if you have to add to or redesign your database to accommodate them.
Go to Top of Page

mmarovic
Aged Yak Warrior

518 Posts

Posted - 2011-03-09 : 03:04:23
Nice explanation Rob! It would be nice to have like option for every post. :)


Mirko

My blog: http://mirko-marovic-eng.blogspot.com/
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-03-09 : 08:23:12
Thanks! Unfortunately I have a full time job and they don't pay me to answer questions on SQLTeam.

Maybe I could get fired again...
Go to Top of Page
   

- Advertisement -