Converting from varchar to Text column

Posted on 2004-11-18
Last Modified: 2012-06-27
We have an MS Access front end to a SQL Server 2000 database. One of the tables has a notes field, which according to our users is not large enough (it's currently the max # characters supported by varchar data type).

I've been asked to enlarge it, which means using Text data type. I'm wondering if there are any issues I need to be aware of before making this change. E.g., LEN doesn't work with Text, DATALENGTH has to be used instead.

Is there anything else? I've done some preliminary tests, and all seems to be ok, but I would like to be sure.

Thanks for any assistance with this,

Question by:TomT49
    LVL 11

    Expert Comment

    The text datatypes cannot be processed in the same way as (n)(var)char datatypes. You cannot use them in functions as you would with chars , nor can you use then in WHERE clause.

    e.g. you cannot do

    SELECT LEFT(textcol, 3)

    SELECT * FROM MyTable WHERE textcol = 'this is a long piece of text.......'

    nor can you sort them.

    if they are < 8000 chars long, you can cast them to varchar to process them - e.g. WHERE convert(varchar(8000), textcol) = 'this is a long piece of text...' etc, but this will slow down your queries substantially.

    As you know, Varchar you can use up to 8000 use TEXT data type only if it is necessary.
    LVL 11

    Expert Comment

    Adding more to this...

    By default, the text, ntext, and image data types don't store their data in the row like the other fields of that row do. Instead, they store a 16 byte pointer that redirects SQL Server to another 8 K page(s) where the data can be found.

    since SQL Server must retrieve two or more pages (verses only one page for rows without any text/image data) using the text, ntext, and image data types slows SQL Server down.
    LVL 1

    Author Comment

    Thanks for your responses. I would prefer to avoid using this if at all possible, the problem is our sales staff want to be able to put in unlimited notes (at least more than they can now - 8000 chars) for line items in orders.

    We do business primarily the government, and apparently things get very complicated.

    Short of telling them no, I'm not sure what the solution could be. Is the performance hit that noticeable? Is there any way to measure the impact?
    LVL 11

    Accepted Solution

    If you are sure of using not using this field in any search criteria's (just a simple select if needed), then it is fine to use TEXT data type. But, if you are not sure of this, as you said better to avoid. Performace impact depends on your database size and the kind of queries you execute.

    Another solution would be (not sure whether it is feasible in your case), split this text into two fields and store in the database..(like field1 varchar(8000), field2 varchar(8000)). Not sure how the user enters this, you can have it in the same way in your application too.

    LVL 16

    Expert Comment

    Or set up a child Notes table, with multiple varchar(8000) records and some sort of process to chunk up long notes and stick them back together, probably in the application code rather than on the SQL Server box.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
    Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
    Via a live example, show how to setup several different housekeeping processes for a SQL Server.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now