Hi,
Responses to your questions are inline.
Now I have a question, does the furniture table hold furniture types or
furnitures instances, please note they are different, a Furniture type are
generics entities ( sofa, chair, loveseat, etc ) with certain properties. A
furniture instance is the black leather sofa placed in the livingroom.
I hope you see the difference. I can show you a UML model with both
escenarios if you need further clarification.
Sharon said:
After looking further to the solution you have suggested, I'm puzzled with
two unclear questions:
(1) If I have 3 rooms and 12 furniture all together, 4 furniture in each
room. How many ROOM_FURNITURE tables will be created in this case that
will
hold the bi-directional relations between the rooms and the furniture
(relations that point from furniture to room and from room to furniture) ?
How the ROOM_FURNITURE will look like?
Only one table !!!
with 3*4 rows
Will look like this ( I scripted a piece of one DB and changed the names of
tables/columns , hope it will be clear enough )
ALTER TABLE [dbo].[Room_Furniture] ADD
CONSTRAINT [Constraint19] PRIMARY KEY NONCLUSTERED
(
[roomID],
[furnitureTypeID]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Room_Furniture] ADD
CONSTRAINT [Constraint18] FOREIGN KEY
(
[roomID]
) REFERENCES [dbo].[RoomTable] (
[pID]
),
CONSTRAINT [Constraint20] FOREIGN KEY
(
[furnitureTypeID]
) REFERENCES [dbo].[FurnitureType] (
[uID]
)
GO
(2) Lets say I'm trying to find the furniture that room 3 contains.
So, I go from room 3 row through its key to the ROOM_FURNITURE row in the
ROOM_FURNITURE table, but now I need to find to which furniture to go to
because there are many furniture in that room or even many furniture for
all
the other rooms.
You can use any of these queries:
SELECT * FROM FurnitureType WHERE FurnitureTypeID in ( SELECT
FurnitureTypeID FROM Room_Furniture WHERE roomID = 3 )
or this other:
SELECT Furniture.* FROM FurnitureType, Room_Furniture WHERE
FurnitureType.FurnitureTypeID = Room_Furniture.FurnitureTypeID AND
Room_Furniture.RoomID = 3
cheeers,