1

I am writing a basic DBMS package and I am trying to retrieve the column length. This is the query I am using to retrieve the infomation:

SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = 'testVariables' 

This works fine, no issues except for CHARACTER_MAXIMUM_LENGTH returns -1 all the time, When I use SQL Management Studio it says the column length is 16...

Any ideas?

Cheers, Joel

2
  • are you connecting with the same user? Commented Jul 17, 2010 at 11:07
  • I don't see any problem - for VARCHAR columns, it does return the proper length. What are you looking for? INT, DATETIME etc. fields do not have a maximum length - their length is a given, defined by their type Commented Jul 17, 2010 at 11:17

1 Answer 1

1

Take a look at look at books online and you will discover that the value -1 for CHARACTER_MAXIMUM_LENGTH means the data type is either XML of a large-value type.

See COLUMNS

Sign up to request clarification or add additional context in comments.

4 Comments

Hello, Thanks for the answer. I read that when researching why It was going wrong - but it should return the value 16 as the column is nVarchar(16) - or am I being thick? Cheers, Joel
I just created a test table with a column nVarchar(16) and it shows up correctly. Are you sure you're in the right database context. Or don't have 2 tables of that name in different schemas?
or the datatype is an INT, DATETIME etc. - just something that's nor (N)VARCHAR, nor (N)CHAR
Hey, yeah I think the problem was the way the table was defined, I will try delete and re-create the table. Cheers, Joel

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.