1

Apologies for the rather basic question.

I have an error string that is built dynamically. The data in the string is passed by various third parties so I don't have any control, nor do I know the ultimate size of the string.

I have a transaction table that currently logs details and I want to include the string so that I can reference back to it if necessary.

2 questions:

  • How should I store it in the database?
  • Should I do anything else such as contrain the string in code?

I'm using Sql Server 2008 Web.

3
  • nvarchar(max) msdn.microsoft.com/en-us/library/ms186939(v=sql.100).aspx, if its bigger than that you are logging too much error information. Commented Aug 15, 2013 at 9:09
  • @Jodrell - thats the thing - I don't know. Theoretically the third party could send an error message for every invalid input field I send them 35 * 100-150 chars Commented Aug 15, 2013 at 9:30
  • @dotnetnoob - So worst case would be 5,250 characters. Unicode or "plain vanilla" Commented Aug 15, 2013 at 9:34

3 Answers 3

1

If you want to store non unicode text, you can use:

varchar(max) or nvarchar(max)

Maximum length is 2GB.

Other alternatives are:

binary or varbinary

Drawbacks: you can't search into these fields and index and order them and the maximum size : 2GB.

There are TEXT and NTEXT, but they will be deprecated in the future, so I don't suggest to use them. They have the same drawbacks as binary.

So the best choice is one of varchar(max) or nvarchar(max).

Sign up to request clarification or add additional context in comments.

2 Comments

[n]varchar(max) is 2GB not 4,000/8,000 characters. So supports 1 or 2 billion characters dependent on single or double byte. There is no need to store as binary.
DV removed but you've still left in the bit about "If you want to store larger strings use bynary or varbynary". This is not correct except if using varbinary(max) in conjunction with filestream. varbinary(max) in the DB has the same 2GB limit.
1

You can use SQL Server nvarchar(MAX).

Check out this too.

3 Comments

When you say "Check this out" are you suggesting the use of ntext or drawing attention to the warning?
Yes actually thats what I wanted as you have already pointed the official link in the comments so I thought to go with this one ;)
I am just trying to draw the attention to the warning!! ;)
1

Eventualy, you can enable and use a FILESTREAM feature of SQL Server 2008 (it's supported by WEB edition), and deal with extra large amount of data in sense of documents.

Of course, you need to be sure that you will use a benefit of this service.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.