Search code examples
sqlsql-serverdatabasenormalizationentity-attribute-value

Normalize SQL table


Can we furthur Normalize this Sql Table Structue is Primary key is ID,Date,NAme,Type

ID  Date          Name            Type           Value 
-----------------------------------------------------


1   08/15/2010    Rating          A+               10       
1   08/15/2010    Rating          A-               10        
1   08/15/2010    Composition     MultipleChoice   33        
1   08/15/2010    Composition     YESNO            33        
1   08/15/2010    Composition     Fillin           33        

1   08/16/2010    Rating          A+               30      
1   08/16/2010    Rating          A-               10        
1   08/16/2010    Composition     MultipleChoice   25       
1   08/16/2010    Composition     YESNO            50        
1   08/16/2010    Composition     Fillin           25      

and so on


Solution

  • This looks suspiciously like a combination EAV table and history table. What is its true purpose? What are the associated tables?

    Based on the limited information given, you would normalize it by turning it into a pure history table. The Rating and Composition should not be split across rows but should be in decently-named columns. Something like so:

    ID  Date          Rating_A+     Rating_A-   MultipleChoicePercent  YESNOPercent FillinPercent
    ---------------------------------------------------------------------------------------------
    1   08/15/2010    10.0          10.0        33.3                    33.3        33.3
    1   08/16/2010    30.0          10.0        25.0                    50.0        25.0
    

    .
    This will allow for simpler and faster: Check constraints, indexes, and queries.