How to store meta-data on columns

前端 未结 9 584
死守一世寂寞
死守一世寂寞 2020-12-28 09:31

Let\'s say you\'re collecting insider info on upcoming superhero movie releases and your main Movie table looks something like this:

Table 1

相关标签:
9条回答
  • 2020-12-28 10:22

    Here's another idea...feel free to punch holes in it :)

    Table: Movie
    Columns: MovieId|Movie|Director|LeadMale|LeadFemale|Villain
    
    Table: MovieSource
    Columns: MovieSourceId|MovieId|MovieRoleId|Source|Journalist
    
    Table: MovieRole
    Columns: MovieRoleId|MovieRole
    Values: 1|Director, 2|LeadMale, 3|LeadFemale, 4|Villain
    

    What I'm thinking is that the columns in the movie table could be of different types (in your example, they are all strings/varchars, but they could be, say, numerical or date information that also has a source).

    The column types for the source data, however, probably wouldn't vary as a function of the column types of the movie data, so you could use more of an EAV system for the source without losing the integrity of your data.

    The MovieRole table allows you to explicitly enumerate the roles so you can create a sure linkage between the source and a given cell of the movie table.

    -Dan

    0 讨论(0)
  • 2020-12-28 10:24

    Seeing as you only have the two fields for source data (Source and Journalist), I would recommend a meta-data table like this:

    Movie    DirectorSource  DirectorJournalist  LeadingMaleSource  LeadingMaleJournalist ...
    ---------------------------------------------------------------------------------------
    The Tick   Yahoo           Cameron           ...                ...
    

    This will keep the less important source data out of the main table, but the queries will not get complicated and your code will be more readable.

    I would only advise EAV if ...

    • You have more than 3 fields of source meta-data
    • You need to be able to add or change movie fields easily. (changes like 'Villain' to 'Primary Villain' are being done several times per day)
    0 讨论(0)
  • 2020-12-28 10:24

    Hmm.... I've not used this, so I'm not speaking from experience (i.e. don't blame me if it doesn't work), but on the surface it seems that you could store "common" data that you know will always be there as you would in a normal table, and "metadata" that might change as XML. The question then is how to query it nicely, and I think you might be able to do that as described HERE.

    0 讨论(0)
提交回复
热议问题