Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Converting from varchar to Text column

Posted on 2004-11-18
6
Medium Priority
?
408 Views
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,

Tom
0
Comment
Question by:TomT49
  • 3
5 Comments
 
LVL 11

Expert Comment

by:ram2098
ID: 12621675
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 chars..so use TEXT data type only if it is necessary.
0
 
LVL 11

Expert Comment

by:ram2098
ID: 12621680
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.
0
 
LVL 1

Author Comment

by:TomT49
ID: 12622047
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?
0
 
LVL 11

Accepted Solution

by:
ram2098 earned 500 total points
ID: 12622099
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.

0
 
LVL 16

Expert Comment

by:muzzy2003
ID: 12623323
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.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

572 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