Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing HTML in SQL Server

What data type should I use to store HTML content in SQL Server 2008?

It's for dynamic content for a CMS.

like image 593
Petrus Theron Avatar asked Apr 24 '11 19:04

Petrus Theron


2 Answers

VARCHAR(MAX) if it's all going to be ascii-based, say for basic HTML tepmplates

NVARCHAR(MAX) if the HTML could contain any content

NVARCHAR will double your storage use as it uses double the amount of space as VARCHAR. HTML itself does not require NVARCHAR, only the content in-between the HTML tags could based on the language, etc..

Edit:

Many years on from giving this answer I almost always use NVARCHAR now if there is any between the tag content. Unicode is popular...

I only use VARCHAR if just storing simple html templates, eg tags and placeholders
eg: <div><span>[PLACEHOLDER]</span><div>

Make the call based on your use-case..

like image 187
Dave Sumter Avatar answered Oct 02 '22 23:10

Dave Sumter


Put it in an NVARCHAR(MAX) (or smaller).
HTML is no different from other text.

like image 22
SLaks Avatar answered Oct 03 '22 00:10

SLaks