I'm currently working on a project that I'm having some design difficulties with and I was hoping that some of you could help me out. What I'm designing is sort of a webbased directory service based on different custom made templates. Imagine the yellow pages with different column requirements for each branch. Example:Template: RestaurantColumns: Name, Adress, TakeAwayTemplate: DBAForHireColumns: Name, Adress, YearsExperienceI have designed a few tables that look like this:DECLARE @templates TABLE (TemplateID INT IDENTITY(1, 1), TemplateName VARCHAR(50))DECLARE @attributes TABLE (AttributeID INT IDENTITY(1, 1), AttributeName VARCHAR(50))DECLARE @template_attributes TABLE (TemplateID INT, AttributeID INT)DECLARE @values TABLE (ValueID INT IDENTITY(1, 1), TemplateID INT, AttributeID INT, Value VARCHAR(200))INSERT INTO @templates SELECT 'Restaurant' UNION ALL SELECT 'DBAForHire'INSERT INTO @attributes SELECT 'Name' UNION ALL SELECT 'Adress' UNION ALL SELECT 'TakeAway' UNION ALL SELECT 'YearsExperience'INSERT INTO @template_attributes SELECT 1, 1 UNION ALL SELECT 1, 2 UNION ALL SELECT 1, 3 UNION ALL SELECT 2, 1 UNION ALL SELECT 2, 2 UNION ALL SELECT 2, 4INSERT INTO @values SELECT 1, 1, 'Lumbagos TexMex' UNION ALL SELECT 1, 2, 'Mainstreet Oslo' UNION ALL SELECT 1, 3, 'Yes' UNION ALL SELECT 2, 1, 'Peso' UNION ALL SELECT 2, 2, 'Somewhere IN Sweden' UNION ALL SELECT 2, 4, '10'SELECT TemplateName, AttributeName, ValueFROM @templates a INNER JOIN @template_attributes b ON a.TemplateID = b.TemplateID INNER JOIN @attributes c ON b.AttributeID = c.AttributeID INNER JOIN @values d ON b.TemplateID = d.TemplateID AND c.AttributeID = d.AttributeID
The problem I need help with is that with the current design all "Values" are defined as varchar(200)...is it possible to change the design so that it's equally flexible but also fasilitates different datatypes? In some cases I would like to have a description column with way more than 200 characters, and I'd also like to save numbers as actual numbers...not like my example above with "YearsExperience". Is it at all possible?? I would appreciate your insight on this...
--Lumbago"Real programmers don't document, if it was hard to write it should be hard to understand"