June 28, 2005 at 6:47 am
Are there any reasons why you should use text over varchar for columns where the maximum length is, 8000 say? I'm aware of the difficulties when performing comparisons against and updating text columns and the fact that using sp_spaceused shows that a table with a text column uses about twice as much space as an equivalent table containing the same data in a column of type varchar(8000).
Should you only use the text data type in situations where you need to store more than 8000 characters?
Thanks in advance for any help.
Sean
June 28, 2005 at 7:07 am
Should you only use the text data type in situations where you need to store more than 8000 characters?
Yes. You should always use the most fitting datatype for any data you want to store.
June 29, 2005 at 2:19 am
Hmm. What about performance? Say your data is always close to 8000 chars and you access it very seldomly. Would it not make sense to make it a text (not in-row) to improve table scans (where the column is not returned?
June 29, 2005 at 3:06 am
Thanks for both of your comments. I've realised that the varchar option has a big impact on the row size in that if a column does actually contain a record with 8000 chars it is dangerously close to the maximum 8060 bytes at which updates will fail. Text seems a better option in this case.
Because it is likely that the column will need to be queried fairly regularly, I've changed the design and reduced the varchar size to keep it the row size below this limit.
June 29, 2005 at 3:09 am
In that case I would probably put the varchar column in a separate table.
June 29, 2005 at 3:22 am
Yeah, I guess you are right. Though the idea might be interesting to consider. An aditional table would be perfect if you could rely 100% on the SQL Servers ability to use vertically partitioned views/tables. Otherwise it might introduce some extra work you might not want to bother with. Or for example if you do not want to dirty your data model
June 29, 2005 at 9:12 am
Also do not forget thw maximum size of all columns of a row is 8060 bytes.
So if you have a column which is declared as a varchar(8000) and if you are filling all of your 8000 bytes then the sum of the size of all remaining columns must not exeed 60 bytes.
If you use nchar, nvarchar, then the max size is nvarchar(4000).
While by using text datatype the size is not limited (or better said it is limited to 2 GB per row).
By using text you can fit more records into one page (8K) therefore you can increase the performance
Bye
Gabor
June 29, 2005 at 9:52 am
'Increase performance'... Yes, if you do not actually access the text that the 16 byte pointers are pointing to. That actually degrades your performance...
June 29, 2005 at 10:01 am
The name of the Game in this case is USAGE. How is it going to be used?
There are many problems associated with data manipulation of text fields the complexity that you may introduce by keeping a separate table with a varchar(8000) are easyly erased by the complexity introduced in manipulating (Updating / Apending / searching within ) text columns. If on the contrary is extremely seldom modified or the contents are rarely parsed then it may be the only case that I would use the text type
Just MY opinion.
* Noel
June 29, 2005 at 11:23 am
Oh, and if my answer still does not convince you have a look at some of the difficuties that this guy had to undergo
http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=194787
just to perform something very simple to accomplish with varchar columns
* Noel
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply