Fábio Antunes
Fábio Antunes

Reputation: 17164

Best data type to store html css javascript

Good day.

I have a PHP & MySql background, and I'm just starting with ASP.NET. I don't have any background with ASP, only have experience with 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.

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:

Thanks.

Upvotes: 3

Views: 1889

Answers (4)

MJ A
MJ A

Reputation: 72

You can use nText or Text
if you have unicode language in your html use nText
nText has unlimited lenght column for your data

Upvotes: 0

gbn
gbn

Reputation: 432210

Use the large text datatypes varchar(max) or nvarchar(max) which allow up to 2GB-1 bytes of data

From MSDN on text and ntext

ntext, text, and image data types will be removed in a future version of Microsoft SQL Server. 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.

Upvotes: 1

Scott
Scott

Reputation: 13921

For future compatibility, use the VARCHAR(MAX) data type. 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. 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. So in a lot of cases the text content will fit in the row, requiring much less disk IO.

Microsoft is said to be deprecating the text and ntext data types in future releases.

Upvotes: 0

Brian Ball
Brian Ball

Reputation: 12596

varchar(#) if you know you will not be storing unicode characters, if you are going to store unicode characters use 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).

Upvotes: 5

Related Questions