在 SQL Server 中存储 HTML [英] Storing HTML in SQL Server

查看:45
本文介绍了在 SQL Server 中存储 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该使用什么数据类型在 SQL Server 2008 中存储 HTML 内容?

用于 CMS 的动态内容.

解决方案

VARCHAR(MAX) 如果一切都基于 ascii,比如基本的 HTML 模板

NVARCHAR(MAX) 如果 HTML 可以包含任何内容

NVARCHAR 将使您的存储使用量增加一倍,因为它使用的空间量是 VARCHAR 的两倍.HTML 本身不需要 NVARCHAR,只有 HTML 标签之间的内容可以基于语言等.

从给出这个答案多年后,如果标签内容之间有任何内容,我现在几乎总是使用 NVARCHAR.Unicode 流行...

我只在存储简单的 html 模板时才使用 VARCHAR,例如标签和占位符
例如:

[PLACEHOLDER]

根据您的用例拨打电话..

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

It's for dynamic content for a CMS.

解决方案

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..

这篇关于在 SQL Server 中存储 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆