简体   繁体   English

存储html css javascript的最佳数据类型

[英]Best data type to store html css javascript

Good day. 美好的一天。

I have a PHP & MySql background, and I'm just starting with ASP.NET. 我有一个PHP和MySql背景,我刚开始使用ASP.NET。 I don't have any background with ASP, only have experience with C#. 我没有任何ASP背景,只有C#经验。

Well my problem its very simple, i would like to be able to save HTML, CSS and Javascript code directly to a MS SQL Server database. 我的问题非常简单,我希望能够将HTML,CSS和Javascript代码直接保存到MS SQL Server数据库。

However i don't know which data type is more advised to store code, bare in mind that i would like to keep the original code formatting (break lines, formating, etc). 但是我不知道更多建议存储代码的数据类型,请记住我想保留原始代码格式(断行,格式化等)。

Any help is appreciated. 任何帮助表示赞赏。

Environment Details: 环境细节:

  • Windows 7 (x86) Windows 7(x86)
  • Visual Studio 2010 Ultimate Visual Studio 2010 Ultimate
  • Sql Server 2008 Sql Server 2008
  • ASP.NET & C# ASP.NET和C#
  • NET Framework 4.0 NET Framework 4.0

Thanks. 谢谢。

varchar(#) if you know you will not be storing unicode characters, if you are going to store unicode characters use nvarchar(#) . varchar(#)如果你知道你不会存储unicode字符,如果要存储unicode字符,请使用nvarchar(#) Replace the # with the max number of characters. 将#替换为最大字符数。 You can also specify max instead of a number and it will store as much as you want (there probably is a limit, but I haven't run into it yet). 您也可以指定max而不是数字,它将尽可能多地存储(可能存在限制,但我还没有遇到过)。

Use the large text datatypes varchar(max) or nvarchar(max) which allow up to 2GB-1 bytes of data 使用大文本数据类型varchar(max)或nvarchar(max) ,允许最多2GB-1字节的数据

From MSDN on text and ntext 从MSDN上的text和ntext

ntext, text, and image data types will be removed in a future version of Microsoft SQL Server. 将来的Microsoft SQL Server版本中将删除ntext,text和image数据类型。 Avoid using these data types in new development work, and plan to modify applications that currently use them. 避免在新的开发工作中使用这些数据类型,并计划修改当前使用它们的应用程序。 Use nvarchar(max), varchar(max), and varbinary(max) instead. 请改用nvarchar(max),varchar(max)和varbinary(max)。

You can use nText or Text 您可以使用nTextText
if you have unicode language in your html use nText 如果你的html中有unicode语言,请使用nText
nText has unlimited lenght column for your data nText具有无限长的数据列

For future compatibility, use the VARCHAR(MAX) data type. 为了将来兼容,请使用VARCHAR(MAX)数据类型。 In SQL Server 2005 Microsoft added support for varchar(max) and nvarchar(max), this new datatype can be used anywhere a regular length limited varchar can, but lets you store up to 2GB of data. 在SQL Server 2005中,Microsoft添加了对varchar(max)和nvarchar(max)的支持,这种新的数据类型可以在常规长度限制varchar可以使用的任何地方使用,但允许您存储最多2GB的数据。 Behind the scenes the varchar(max) stores up to as much of the text as it can in the row (up to 8K), and then creates additional pages for any additional text. 在幕后,varchar(max)可存储尽可能多的文本(最多8K),然后为任何其他文本创建其他页面。 So in a lot of cases the text content will fit in the row, requiring much less disk IO. 因此,在很多情况下,文本内容将适合行,需要更少的磁盘IO。

Microsoft is said to be deprecating the text and ntext data types in future releases. 据说微软在将来的版本中弃用了text和ntext数据类型。

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

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