Pregunta

Example: a database containing the names and properties of different metals (density, colour, melting point etc.) where I might have found the value for the density from one source (website, book, ...) and the melting point from another and I want to make it retrievable from which source any given value came.

The simple solution is to create a column 'Density' and a column 'Density Source' and so on for all properties but this seems like a very verbose way of solving this. Yes, 'Density Source' could be a simple integer with another table spelling out the source.

In a sense, I am looking to add something like a footnote to a field.

¿Fue útil?

Solución

The tough answer is that you're not going to get anywhere with anything less verbose than have a source table and then having a link back to each source for each bit of information.

What you can do is create the matrix of possible sources for your density, color, melting point, etc. and then assign a universal "SourceKey" for that, so that you would only have to store one source on the actual property table. Then, to get the density source, you'd do this:

select
    s.SourceName as DensitySource,
    m.*
from
    metals m
    inner join SourceMatrix sm on
        m.SourceKey = sm.SourceKey
    inner join Source s on
        sm.DensitySourceKey = s.SourceKey

That completely depends on how many combinations you can have and whether or not that's efficient at all, though. The database stores relations, but it doesn't store lineage.

Otros consejos

If you want to flag the entire column, you could use SQL Server's extended properties or MySQL COMMENT options. These are "outside" of the relational design of your database

If you want to flag per column and per row, add another column, because it is relevant data to store in the model

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top