简体   繁体   English

在sql server中存储html内容和其他文档(pdf,word,excel)?

[英]Storing html content and other documents (pdf, word, excel) in sql server?

What datatype is the best to store html content and documents like pdf's, excel files, and word documents. 什么数据类型最好存储html内容和文档,如pdf,excel文件和word文档。 I am currently using ntext, but I am not sure if this is the best datatype to store html content. 我目前正在使用ntext,但我不确定这是否是存储html内容的最佳数据类型。

Also, I currently use FCKEditor to save html content to an ntext field and it stores the markup along with the styles. 此外,我目前使用FCKEditor将html内容保存到ntext字段,并将标记与样式一起存储。 If I happen to read the part of the description into an ItemTemplate of a ListView with the following: 如果我碰巧将描述的一部分读入ListView的ItemTemplate,其中包含以下内容:

<%# Eval("content") %>

It displays the content, but it displays the markup as well. 它显示内容,但也显示标记。 For example, instead of displaying: 例如,而不是显示:

"This is an html string" , it would display <p>This is and html <b>string</b></p> "This is an html string" ,它会显示<p>This is and html <b>string</b></p>

I would store the HTML in NVARCHAR(MAX) (or less if you don't need more than 4000 characters). 我会将HTML存储在NVARCHAR(MAX)中(如果不需要超过4000个字符,则会更少)。 Don't use the TEXT/NTEXT data type unless you are stuck in SQL Server 2000. They're deprecated and the benefits of the MAX types make their usage foolhardy IMHO. 不要使用TEXT / NTEXT数据类型,除非你被卡在SQL Server 2000中。它们已被弃用,MAX类型的好处使它们的使用变得愚蠢恕我直言。

I would investigate storing the files as FILESTREAM in SQL Server 2008. If you are < 2008, or you have investigated the trade-offs and FILESTREAM is not an option, then my personal preference is to store files on the file system, and a local and/or http reference to the file in the database. 我会调查将文件存储为SQL Server 2008中的FILESTREAM。如果您是<2008,或者您已经调查了权衡并且FILESTREAM不是一个选项,那么我个人的偏好是将文件存储在文件系统上,以及本地和/或对数据库中文件的http引用。

The benefit of storing the files in the database is that you get transactional consistency. 将文件存储在数据库中的好处是可以获得事务一致性。 The downside is that you use much more database space, which is usually on more expensive storage. 缺点是你使用了更多的数据库空间,这通常是在更昂贵的存储上。 You also have a much harder time debugging (you can't just say "SELECT PDFFile FROM Table" in Management Studio, and expect Acrobat Reader to pop up and show your column's contents). 你也有更难的调试时间(你不能在Management Studio中说“SELECT PDFFile FROM Table”,并期望Acrobat Reader弹出并显示你的专栏内容)。

Since at work I have to beg and sign over the rights to my unborn children for more SAN allocation, and at play I get charged a lot more for my database space usage than my file space usage, I opt for file-based storage every time. 由于在工作中我不得不乞求并签署了的权利,我未出生的孩子更多的SAN配置,并在作怪我得到收取了很多对我的数据库空间使用情况比我的文件空间使用情况,我选择每次基于文件的存储。 At work our file system is backed up and, while it is not 100% in sync with the database backups, we have seen so few file corruption issues that weren't the fault of the end user (and easily corrected without our involvement) - zero, in fact - that it doesn't seem worth it to investigate. 在工作中,我们的文件系统已经备份,虽然它与数据库备份不是100%同步,但我们看到的文件损坏问题很少,而不是最终用户的错误(如果没有我们的参与,很容易纠正) - 实际上是零 - 调查似乎不值得。

Like I said, personal preference. 就像我说的,个人喜好。 But ask the right questions and understand your goals and limitations. 但要问正确的问题,了解你的目标和限制。

  • Store Unicode HTML as ntext 将Unicode HTML存储为ntext
  • If you're 110% sure you'll only need ascii, you can use text or varchar. 如果您确定110%只需要ascii,则可以使用text或varchar。
  • Store binaries (pdf, word, excel) as binary blobs 将二进制文件(pdf,word,excel)存储为二进制blob

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM