Re: [PHP-DB] novice on table design

2005-05-16 Thread Jeremiah Fisher
Addresses should definitely have their own table.
Have you considered using Postgres? It allows for table inheritance in 
much the same way that inheritance works in OOP. You could have a parent 
table (like a parent class) for People, and child tables (just like 
child classes) for Employee, non-Customer, and Customer. This is 
the preferred approach, but few other RDMBS solutions support this (or 
much SQL 99 at all).

If you're not using Postgres, another way to do this would be to create 
a many-to-many relationship between your People tables, so that an 
address ID is related to a person ID.

Visio balks at using a non-unique foreign key because this is bad 
design. A key must be unique by nature, and indexing is much faster 
the column is guaranteed to have unique values. If you go with your 
original approach, make a combined key on both the type and foreign key 
fields.

Hope this helps,
Jeremy

Tony Yau wrote:
Hi Tony, Miguel
yes that was my intention at first, but to absorb all three, Shop,
Employee, and Customer (and there may be 2 more to come) into an Address
table would be inefficient both in storage space and search time,..no?
having this compound keys at a separate Address table is essentially the
same idea, but I know it doesn't 'feel' right, for a start in Visio I can't
put a link to the Address table (because fkey can't be a foreign key to both
Shop and Employee)!!!
Apart from that, the tables are efficient, searching would be much quicker
for non-address info.
Tony
Tony S. Wu [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
actually, no, Shop, Employee, and Customer are not distinct.
in your instance they are the same type of entry.
don't distinguish them by tables, rather use a column to hold some sort
of an ID for each type.
of course you'll end up with a table with many columns, and many of
them will be null depending on which type an entry is.
but with this approach, you can easily associate with an address table.
Tony S. Wu
[EMAIL PROTECTED]

On May 14, 2005, at 4:49 AM, tony yau wrote:

Hi Miguel,
   Thanks for the reply.
   the non-customer is actually a Shop, so Employee, Customer and
Shop are
distinct enough to have their own tables. Now they all have an
Address, and
the problem is how do I allow multiple addresses for each these
'people'
(without using
a lookup table)
tony.
Miguel Guirao [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
The schema of your table is wrong, is you do bnormalize it you will
find
out
that you need two tables for this approach.
One table for your people and another one for the n addresses of your
people.
If you keep your current schema, you will have as many rows for one
person
as many addresses for that person you have, and you will be
duplicating
many
fields. So you must split your tables, one for your people and
another for
your people's addresses.
-Original Message-
From: tony yau [mailto:[EMAIL PROTECTED]
Sent: Viernes, 13 de Mayo de 2005 09:27 a.m.
To: php-db@lists.php.net
Subject: [PHP-DB] novice on table design

Hi all,
I have the following tables
   EmployeeCustomernon-Customer
Address
=======
   pkey pkeypkey
pkey
   number type type
...
   payrate grantcapital
I need to allow the three types of people to have n addresses, so I've
added
a type to distinguish the 3 types of people and their respective pkey
onto
address table.
   Address
=
   pkey
   ...
   type(either Employee, Customer or non-Customer etc)
   fkey(the pkey of Employee, Customer or non-Customer etc)
I know this design looks awkward but it does have the advantage of
having
less tables otherwise.
BUT somehow it doesn't feel right. Can someone points me its pros and
cons.
thanks all.
Tony Yau
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] Re: recommending a PHP book?

2005-03-15 Thread Jeremiah Fisher
PHP 5 Power Programming by Andi Gutmans, Stig Bakken, and Derick 
Rethans may be worth the read for you. It doesn't mention an MVC, but 
they do talk a little about patterns in PHP.

However, you probably won't find much in-depth coverage of patterns in 
PHP. There are alot of good books written on patterns in C++, Java, and 
C#, but PHP doesn't have that enterprise stigma about it.

I've nearly finished an MVC-based framework in PHP, and think that Java 
should be sincerely evaluated before you take up the endeavor. I've had 
to reinvent alot of Struts functionality. Not only that, but you'll 
probably go further with J2EE on your resume than PHP.

O'Reilly has some good books on design patterns. I picked up Head First 
myself, and though it was repetitive, it got the point across pretty 
well. You'll find that most of the code is in Java, but it should be 
easy to read if you speak PHP 5.

For a quick online reference of some common design patterns (and if you 
can read C#), you can look at this site: 
http://www.dofactory.com/Patterns/Patterns.aspx#list

Thanks,
Jeremy
Danny Lin wrote:
Can any one recommend a good book that discusses MVC design patterns with
PHP (and mySQL)?
Thanks.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php