I have an application that allows users to edit certain parts of text and then email that out. My question is what is the best way to store this in a Microsoft SQL Server database. Right now I have two tables, one holding the HTML data and one holding the plain text data. When the user saves the info, it replaces newlines with br's and puts it in the HTML-conntaining table and then puts the regular text in the other table. This way the text box has the newlines when they go to edit, but the table that contains the HTML data, has the BR's. This seems like a silly way to do things. What would be the best practice? Thanks.
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
It's not silly at all.
Consider the following possibilities:
If there is a thing which is annoying, it's the fact that you are using two tables. Why not keeping this data in a single table, with one column for original text, and another column for HTML?
¹ Remember one rule: don't guess what is slowing the application down: use a profiler. Discussing which approach is faster is good for an informal talk with your friends, but not a good approach to develop a scalable application without doing unnecessary work. My example of saving HTML vs. generating it on the fly, for example, is only good in theory. In practice, (1) you'll cache the results anyway, and (2) maybe, who knows, loading the data from the database may be much slower than generating HTML.
If it were me, I would just replace the newlines with br's as the text is being used. So, store the plain text (newlines), and then when you have to use it in an email, replace the newlines with br's on the fly.
You might consider an implementation of BBCode. This will allow you to store plain text, which can be converted to HTML. No actual HTML tags would be allowed.
and so on.