Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Large field question

Author  Topic 

eschoof
Starting Member

4 Posts

Posted - 2003-11-06 : 22:08:46
I am designing a table that could potentially have a field that stores a VERY long string (in upwards of several thousand characters). Is there an efficient way to do this, while also maintaining good performance? I suppose that I should also mention that most of the entries will be short, but a few will be long.

Thanks in advance!

-Eric

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-11-06 : 22:26:22
Hi

If the string could be longer than 8k, Text fields are probably your best bet.
http://www.sqlteam.com/item.asp?ItemID=202 has some info (although, it is aimed at SQL7).



Damian
Go to Top of Page

eschoof
Starting Member

4 Posts

Posted - 2003-11-06 : 22:34:53
Well, say I go with a varchar of 8000 bytes. Does this always make the field 8000 bytes, or is that just the maximum it can hold? I don't want my database to get huge really fast, especially if it really isn't holding that much data.

-Eric
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-11-06 : 22:47:32
A varchar field resizes itself. So if you were to have a varchar(8000) it will only be that size if you fill it that much.

BUT

Your row (if you don't include the Text datatype) can hold 8k. That's 8K per record.
If you try to insert more than that, your insert will fail.

So, although you can declare a table like :

Create Table MyTable
(
recordID int,
recordDesc varchar(500),
recordBody varchar(8000)
)

It will fail if you push more than 8K into a record.

So, this would work :

INSERT INTO MyTable (recordID, recordDesc, recordBody)
VALUES (1, 'blah', 'blah')

but if you did an insert that pushed each of those varchar's to their limit it would fail.

Make sense ?


Damian
Go to Top of Page

eschoof
Starting Member

4 Posts

Posted - 2003-11-06 : 22:49:56
Yep!

Thanks so much for your help.

I'm just now beginning with SQL. I've been reading lots of books, and lots of websites on the subject. Man, there is a LOT out there, lol. I really appreciate all the help, especially since this is probably a FAQ.

-Eric
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-11-06 : 23:05:41
No probs.
Stick around here, you'll be an expert in no time


Damian
Go to Top of Page
   

- Advertisement -