Re: Table design teaser
From: Geoff N. Hiten (SRDBA_at_Careerbuilder.com)
Date: 04/28/04
- Next message: ME: "Re: SQL Script to compare indexes on 2 different databases"
- Previous message: Keith Harris: "Table design teaser"
- In reply to: Keith Harris: "Table design teaser"
- Next in thread: Don Peterson: "Re: Table design teaser"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 28 Apr 2004 15:23:00 -0400
Drop the distinction between staff and customer. Have a 'SENDER' table with
an enumerated status (customer, staff, BOSS,, etc) field.
-- Geoff N. Hiten Microsoft SQL Server MVP Senior Database Administrator Careerbuilder.com I support the Professional Association for SQL Server www.sqlpass.org "Keith Harris" <anonymous@discussions.microsoft.com> wrote in message news:EBE8A8D3-8AAF-434A-961C-2198482B6F72@microsoft.com... > Hi and thanks in advance for any help. > > I am developing a system for message delivery and pondering what is the best table design. > > Here's the situation: > A staff member may send a message to a customer or another staff member > A customer may send a message to a staff member or another customer > > I have the following tables: > > STAFF (ID int pk, Name varchar(50)) > CUSTOMER (ID int pk, Name varchar(50)) > MESSAGE (ID int pk, Body varchar(200), FromID int, ToID int) > > Here are some sample rows from the tables: > > **************************************************************************** ****** > STAFF > ----- > 101, keith > 102, kenneth > 103, Steven > > CUSTOMER > -------- > 101, charles > 102, annette > 103, tom > > MESSAGE > ------- > 101, message from kenneth to keith, 102, 101 > 102, message from kenneth to charles, 102, 101 > 103, message from charles to keith, 101, 101 > 104, message from annette to keith, 102, 101 > > **************************************************************************** ****** > > The problem is that MESSAGE.FromID and MESSAGE.ToID can relate to either STAFF.ID or CUSTOMER.ID. > > i.e. Does message 104 go to keith or charles? Is message 104 from kenneth or annette? > > I could create multiple link tables: > > **************************************************************************** ****** > 1. STAFF_CUSTOMER_MESSAGES (FromID int, ToID int) > 2. STAFF_STAFF_MESSAGES (FromID int, ToID int) > 3. CUSTOMER_STAFF_MESSAGES (FromID int, ToID int) > 4. CUSTOMER_CUSTOMER_MESSAGES (FromID int, ToID int) > > But this seems inelegant. > > **************************************************************************** ****** > I could also design a MESSAGE_LINK table like this: > > MESSAGE_LINK (Message_ID int, FromID int, FromTable varchar(10), ToID int, ToTable varchar(10)) > > giving this sample data: > > **************************************************************************** ****** > MESSAGE_LINK > ------------ > 101, 102, 'STAFF', 101, 'STAFF' > 102, 102, 'STAFF', 101, 'CUSTOMER' > 103, 101, 'CUSTOMER', 101, 'STAFF' > 104, 102, 'CUSTOMER', 101, 'STAFF' > > and this doesn't seem desireable either. Does anyone have a suggestion as to the best way to design this type of relationship? >
- Next message: ME: "Re: SQL Script to compare indexes on 2 different databases"
- Previous message: Keith Harris: "Table design teaser"
- In reply to: Keith Harris: "Table design teaser"
- Next in thread: Don Peterson: "Re: Table design teaser"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|