Reputation: 17164
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
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
Reputation: 432210
Use the large text datatypes varchar(max) or nvarchar(max) which allow up to 2GB-1 bytes of data
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
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
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