best way to store very variable length string in sql table

S

Steve Richter

The strings I want to store in an SQL table will 99% of the time be
short, 128 characters or less. But they could be much longer ( the
RawUrl from the asp.net Request object ).

What is the best way to declare such a string?

Will I be wasting a lot of space if I declare the column as
VarChar(9999)? Or do strings in SQL just use the actual length of the
string?

thanks,

-Steve
 
M

Marina

I believe varchar columns will only take up the space of the characters
actually being stored in them.

Columns declared as 'char', are the ones that are always a fixed length
regardless of the values being stored.
 
S

Steve Richter

Marina said:
I believe varchar columns will only take up the space of the characters
actually being stored in them.

Columns declared as 'char', are the ones that are always a fixed length
regardless of the values being stored.

ok, thank you Marina.

-Steve
 
M

Miha Markic [MVP C#]

Hi Marina,

Marina said:
I believe varchar columns will only take up the space of the characters
actually being stored in them.

To be more precise, it stores actual characters plus some metadata (few
bytes) :)
Columns declared as 'char', are the ones that are always a fixed length
regardless of the values being stored.

Right.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top