sql - Storing Searching Records Based on Multiple Conditions -
i have table of people quite standard stuff e.g. :
create table [contact]( [contactid] [bigint] identity(1,1) not null, [contacttype] [nvarchar](50) null, [forename] [nvarchar](60) null, [surname] [nvarchar](60) null, [company] [nvarchar](60) null } example data : 01, "student", "bob", "smith", blank 02, "staff", "robert", "smithe", "roberts , sons" etc
this table contains fields common contacts. have "types" of contact may or may not have field specic type of contact. example if record has "contacttype='student'" want store field called "studentid". there many different types of contact each different field requirements. add situation @ somepoint in future each contact type might have fields added.
if add each field contacts table end lots of fields not required 99% of records. planning on creating second table this:
create table [contactmetadata]( [contactid] [bigint] not null, [propname] [nvarchar](200) not null, [propdata] [nvarchar](200) null ) example data: 01, "studentid", "0123456" 01, "coursename", "it" 01, "average", "10" 02, "ranking", "22" 02, "producttypes", "it equipment" etc
for each field add record table name , value field. can use code pull information etc.
my question is
is best approach i'm stumped of way other huge table every single field. given approach possible complex querys across many of property fields , if how? e.g. how list students on "it" course "average" of 10 whos "forename" starts "d"?
yes, if have many many fields not used, go approach (called eav data structure). can queries on structure can normal model, use appropriate joins pivot them.
Comments
Post a Comment