在 SQL Server 中存储 HTML
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5772897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Storing HTML in SQL Server
提问by Petrus Theron
What data type should I use to store HTML content in SQL Server 2008?
我应该使用什么数据类型在 SQL Server 2008 中存储 HTML 内容?
It's for dynamic content for a CMS.
它用于 CMS 的动态内容。
回答by Dave Sumter
VARCHAR(MAX)
if it's all going to be ascii-based, say for basic HTML tepmplates
VARCHAR(MAX)
如果这一切都是基于 ascii 的,比如说基本的 HTML 模板
NVARCHAR(MAX)
if the HTML could contain any content
NVARCHAR(MAX)
如果 HTML 可以包含任何内容
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..
NVARCHAR 将使您的存储使用量增加一倍,因为它使用的空间量是 VARCHAR 的两倍。HTML 本身不需要 NVARCHAR,只有 HTML 标签之间的内容可以基于语言等。
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...
从给出这个答案多年后,如果标签内容之间有任何内容,我现在几乎总是使用 NVARCHAR。Unicode 很流行...
I only use VARCHAR if just storing simple html templates, eg tags and placeholders
eg: <div><span>[PLACEHOLDER]</span><div>
如果只存储简单的 html 模板,例如标签和占位符,我只使用 VARCHAR,
例如: <div><span>[PLACEHOLDER]</span><div>
Make the call based on your use-case..
根据您的用例拨打电话..
回答by SLaks
Put it in an NVARCHAR(MAX)
(or smaller).
HTML is no different from other text.
把它放在一个NVARCHAR(MAX)
(或更小)里。
HTML 与其他文本没有什么不同。
回答by Sangeet Shah
Data type should I use to store HTML content in SQL Server 2008
我应该使用数据类型在 SQL Server 2008 中存储 HTML 内容
You must used Nvarchar(Max)if you want to store multiple language text.
如果要存储多语言文本,则必须使用Nvarchar(Max)。
otherwise use VARCHAR(MAX)if you want to store English language text.
否则,如果要存储英语文本,请使用VARCHAR(MAX)。
nvarchar(max) contain more amount of spance compare to varchar(max)
与 varchar(max) 相比,nvarchar(max) 包含更多的空间