views:

112

answers:

1

what is the suitable data type to save string more than 8000 character in SQL database?

+2  A: 

For SQL Server 2005+ varchar(max) or nvarchar(max) depending on whether you need to save as unicode or not.

If you don't have this requirement (or anticipate ever needing it) the varchar option is more space efficient.

You don't give a specific version of SQL Server in your question. Pre 2005 it would have been the text datatype.

NB: In answer to your comment use 'varchar(max)' exactly as written. Don't substitute a number in for "max"!

Martin Smith
I tried varchar(max) and nvarchar(max) but failed because max = 4000 for nvar and 8000 for var
salamonti
I do this but it failed
salamonti
Can you post the full piece of code that fails? Or explain in what context you are using it and getting a problem?
Martin Smith
@salamonti: varchar(max) can **definitely** handle a lot more than 8000 characters! THere must be something else that's wrong with your SQL code or process - please post more info!
marc_s
@salamonti You seem to have completely disregarded the request for further details but one more guess might be that if you are using it in ADO.NET in a place that requires a number you need to use -1.
Martin Smith
sorry but it is worked good sorry for late the problem not in the data type I solved the problem and now working perfect thanks for help
salamonti