what is the suitable data type to save string more than 8000 character in SQL database?
Asked
Active
Viewed 2,405 times
1
-
2It's not clear what your problem is. Is `CREATE TABLE` failing? Or are you trying to `declare @theString varchar(max)`? – egrunin May 23 '10 at 05:47
1 Answers
2
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
- 438,706
- 87
- 741
- 845
-
I tried varchar(max) and nvarchar(max) but failed because max = 4000 for nvar and 8000 for var – kartal May 22 '10 at 22:11
-
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 May 22 '10 at 22:25
-
@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 May 23 '10 at 08:02
-
@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 May 23 '10 at 09:35
-
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 – kartal May 24 '10 at 00:02