I have a main concept - Mail message and two derived concepts :
- template-generated emails
- free-form emails
I am thinking of creating three tables to hold the data and I need your opinions on this matter (if it's bad, if it's good, how can it be improved and so on) :
MailMessages
- Id [int] identity (autoincrement) PK
- ToAddress [varchar(300)]
- IsTemplateBased [bit]
- TemplateId [int] nullable FK
- MailBodyId [int] nullable FK (TemplateId must be null and MailBodyId must be non-null or vice-versa)
- StatusId [tinyint] FK
MailParams
- MailMessageId [int] PFK
- ParamNumber [tinyint]
- Value [nvarchar(4000)]
MailBody
- MailMessageId [int] PFK
- FromUsername [varchar(30)]
- FromDomainId [tinyint] FK
- PlainTextContent [nvarchar(max)]
- HtmlContent [nvarchar(max)] nullable
A few explanations are in order here :
- I would like a design as normalized as possible
- The IsTemplateBased bit (boolean) column can be omitted and the nature of the mail message can be inferred from TemplateId and/or MailBodyId (i.e.: if TemplateId is not null then it's template-based) but I think this de-normalization (?) could be useful for performance
- The reason behind having two columns (FromUsername and FromDomainId) is to enforce email sanity rules - I don't consider having a single column (FromAddress) as being appropiate
Having said all these, what are your opinions, dear readers?