Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I dont feel qualified to comment on what is best, or on design approaches. In fact I'm inclined not to answer at all. However I have thought about your problem and that you've taken the time to describe it clearly, and this is how I would approach it.</p> <p>I'd store each metadata datatype in its own table; So</p> <pre><code>Table MetaData_Text: ID int identity EntryID int KeyName nvarchar(50) KeyValue nvarchar(max) </code></pre> <p>MetaData_DateTime, MetaData_Boolean &amp; MetaData_Numeric have the same structure as this, but with the appropriate different datatype of the KeyValue column in each case.</p> <p>The relationship between an Entry &amp; each of these tables is 0-Many; While every row in each of these tables belongs to one Entry.</p> <p>To add a new metadata item for an entry, I'd just use a stored procedure taking EntryID, keyname &amp; having optional parameters of possible metadata datatype:</p> <pre><code> create procedure AddMetaData @entryid int, @keyname varchar(50), @textvalue varchar(max) = null, @datevalue datetime = null, @boolvalue bool = null, @numvalue float = null as ... </code></pre> <p>For querying, I would define a set of functions to manage each type of (a) metadata datatype &amp; (b) test needing to be performed on that datatype, for example:</p> <pre><code> create function MetaData_HasDate_EQ(@entryid int, @keyname varchar(50), @val datetime) returns bool as begin declare @rv bool select @rv = case when exists( select 1 from MetaData_DateTime where EntryID = @entryid and KeyName = @keyname and KeyValue = @val) then 1 else 0 end; return @rv end </code></pre> <p>and incorporate function references into required query logic as per</p> <pre><code> SELECT ... FROM entry e ... WHERE (dbo.MetaData_HasText_EQ(e.EntryID, 'KeyName1', 'Test12345') &lt;&gt; 0 AND dbo.MetaData_HasDate_Btwn(e.EntryID, 'KeyName2', '01.09.2012 00:00:00', '01.04.2013 23:59:00') &lt;&gt; 0) OR (dbo.MetaData_HasNum_GT(e.EntryID, 'KeyName3', 15.3) &lt;&gt; 0 AND dbo.MetaData_HasBool_EQ(e.EntryID, 'KeyName4', 1) &lt;&gt; 0) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload