x

storing html in database

what are the best practices for storing html in database ( if at all )? should it be stored as html ( in a varchar max field ) or converted to xml ( in which case how should the conversion be handled )? thanks

more ▼

asked Mar 31, 2010 at 08:01 PM in Default

user-1497 (google) gravatar image

user-1497 (google)
1 1 1 1

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

If you really must store HTML then store it as HTML in a varchar(max). If you store it as XML then as you say something somewhere needs to convert it, and I doubt you would be using any of the XML support in SQL.

In the past I have stored raw HTML (and compressed HTML) in varchar(max).

If it's not real data, then just think of it as a piece of data, and you just need a datatype big enough to store it.

more ▼

answered Mar 31, 2010 at 08:07 PM

Kev Riley gravatar image

Kev Riley ♦♦
52.8k 47 49 76

+1 Great explanation.
Mar 31, 2010 at 11:33 PM Tom Staab
+1 agreed with this assertion.
Apr 01, 2010 at 02:16 AM CirqueDeSQLeil
+1 - yup .
Apr 01, 2010 at 03:42 AM Fatherjack ♦♦
I definitely wouldn't try converting it in any way. That would add overhead to both saving and fetching, and something is bound to end up getting mangled sooner or later.
Apr 01, 2010 at 06:03 AM David Wimbush
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x147
x30

asked: Mar 31, 2010 at 08:01 PM

Seen: 2502 times

Last Updated: Mar 31, 2010 at 08:01 PM