Hi folks,
EDIT1: Tried to clear the question up by renaming the tables AND their relationships. EDIT2: Please don't look at the what TYPE of data i'm holding in the three DB tables. They were made up on the fly. They are NOT my real world scenarios (and no, I can't talk about my real world data .. in fact it's 1 parent and 6 children, currently). Please just ignore what type of data and just look at the fact that some data is required. EDIT3: The two FKs are a 0 or 1 to 1 relationship. NOT 0 to many. Not 1 to 1. I'm trying to avoid the 0 or 1 to 1 relationship to a 1 to 1 relationship so i don't need to have OUTER JOINS but instead have an INNER JOIN.
Question: I need to know if the proposed database design is good/bad/lame/etc..
Problem: today i tried to make an indexed view, but failed 'cause my tables have outer joins. Sigh. So i was wondering if i can refix this up to be like the following design:
- Three tables.
- table_User has a FK on table_Address
- table_User has an FK on table_Vehicle
- etc..
and table B and C (which sorta act like lookup tables now) have..
- Id INT IDENTITY PK
- Description NVARCHAR(100) NULLABLE
notice the nullable? this way, something in table_User doesn't exist in table_Address ... the the field is null (because of the inner join).
Before, i made that an LEFT OUTER JOIN, so if there was no data in table_b, i'll get nulls are the result for each field.
I'll throw some data examples here...
Table_User
- ID: 1, Name: Fred, AddressID: 1 (NULL)
- ID: 2, Name: Joe, AddressID: 2 (1 smith street.....)
- ID: 3, Name: Jane, AddressID: 2 (1 smith street.....)
Table_Address
- ID: 1, Description = NULL
- ID: 2, Description = 1 smith street
etc.
So then i can finally put this all into an indexed view. (my real life scenario has around 8 tables).
NOTE: DB is Microsoft Sql Server 2008, but this could be for any DB.
Q1: Does that design seem ok?
Q2: So what i'm doing here is i'm normalising the data, right? by keeping the inner joins together.
Q3:Lastly, if this is an ok way about it .. can i also make sure the data in the tables are unique (eg. the street addresses) by having some unique constraints or keys or indexes or what (i'm not sure of the proper terminology).
thanks gurus!