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 2005 Forums
 Transact-SQL (2005)
 Data length 'max'

Author  Topic 

sathyav
Starting Member

27 Posts

Posted - 2007-01-11 : 00:02:17
Hi all,

I ve few queries, kindly help me to understand the things,

1. Datatypes like nvarchar, varchar, varbinary use 'max' to define their datalength,

a. is this 'max' always has the value of 2^31-1 ?
b. what other data types in sqlserver 2005 can use 'max' to define their datalength?

2. I defined a table say 't' with a column 'name' of datatype nvarchar(max), now tried to execute the below query in the SQLServer client,

select column_name, data_type, character_maximum_length from information_schema.columns where table_name='t'


the result is,

+--------------+------------+--------------------------+
| column_name | data_type | character_maximum_length |
+--------------+------------+--------------------------+
| name | nvarchar | -1 |
+--------------+------------+--------------------------+

The question is why the datatype length is returned as -1, what happened to 'max'?
is there any other way to retrieve the actual data length (ie., 'max') from the table definition?

Thanks in advance,



Today will be Yesterday Tomorrow - Do it now

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-01-11 : 00:47:59
from BOL:

CHARACTER_MAXIMUM_LENGTH int

Maximum length, in characters, for binary data, character data, or text and image data.

-1 for xml and large-value type data. Otherwise, NULL is returned. For more information, see Data Types (Transact-SQL).

http://msdn2.microsoft.com/en-us/library/ms188348.aspx


www.elsasoft.org
Go to Top of Page

sathyav
Starting Member

27 Posts

Posted - 2007-01-11 : 03:36:08
Thank you, i got the required info.

cheers!!


Today will be Yesterday Tomorrow - Do it now
Go to Top of Page
   

- Advertisement -