Wednesday, May 27, 2009

varchar(max) in sql server 2005

Varchar(max) is one of the new type data of sql server 2005.

Usually we use it when we didn't know the maximum length of string or we couldn't expect how long the string is.

As you know the length of varchar(max) is -1. We'll see when we're using ALT+F1 at table name. Or we could using this query to figure it out :

---------------------------------------------------------------------------
drop table test1

create table test1
(
strMax varchar(max)
)

select distinct b.name, a.name, c.name, a.max_length,c.precision, c.scale
from
sys.columns a left join sys.objects b
on a.object_id = b.object_id
left join sys.types c
on c.system_type_id = a.system_type_id
and c.user_type_id = a.user_type_id
where b.name = 'test1'
----------------------------------------------------------------------------

Here the results :

name name name max_length precision scale
test1 strMax varchar -1 0 0


Regards,

Wihemdra

No comments:

Post a Comment