Question : Database Design Question -  SQL Server

Hi, everyone:

Here is the problem:
- data from the website, from a drop down list for a search is passed top the database
- the data passed and saved in the DB - "Sales Type" is saved into a table called MVO as a string (multivalued string, comma delimited)

- "Sales Type" can be one of seven types, "Auction", "Foreclosure", "REO", etc.

* I need to take that column and save it into a normalized data-structure.

The PKey of the MVO table (above) is mlsnum

I took two design alternatives:
First Design
1. created a Lookup table with the different "Sales types", PKey SaleTypeID
2. created a "Junction-table", with Composite Keys, mlsNum, SaleTypeID with 1-Many relationship to both the lookup table and the MVO table.

Second Design:
- Created a single Table, MVO_SaleType with PKey mlsnum and seven other columns;
IsAuction, IsForeclosure, IsREO, etc.  these are all bit columns

Well, the first design approach appears to be in 3rd NF and all but it is very difficult to write the correct, optimized query using that design - I particularly an not "allowed" to use new features of SQL 2005/2008 (because of pushback from developers ...)

I will appreciate your comment and/or advice, criticism.

I have attached a document the shows the design and details.

Thank you in advance.

Dan
Attachments:
 
 

Answer : Database Design Question -  SQL Server

With your first design, you could do a join between mls_unified_mvo_svo_tbl and a subquery that groups on mls_unified_mvo_sale_type.  E.g.,

select a.mlsnum, b.SaleTypeName, b.NameCount from
  mls_unified_mvo_svo_tbl a inner join
  (select MlsNum, SaleTypeName, Count(SaleTypeName) as NameCount
    from mls_unified_mvo_svo_sale_type inner join sale_type
    group by MlsNum, SaleTypeName) b on a.MlsNum = b.MlsNum
where b.SaleTypeName in ('Auction', 'Foreclosure') and b.NameCount > 0;

This join will produce no more than one record for each discrete Sales_Type value, so you can simply select the ones you want and ignore the rest.

HOWEVER, I'm sure the second design will perform a lot better.  This is probably one of those times where you trade normalization for performance.
Random Solutions  
 
programming4us programming4us