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
 Transact-SQL (2000)
 How to determine the defined column lengths ?

Author  Topic 

Utpal
Posting Yak Master

179 Posts

Posted - 2002-07-16 : 04:15:09
Hi everybody,
Is it possible to determine the defined lengths of columns in a table ? I tried :
Select COLUMN_NAME, CHARACTER_MAXIMUM_LENGTH from information_schema.columns WHERE TABLE_NAME = "Item_Master"

, but this returns the length only if data is present in the columns.


nr
SQLTeam MVY

12543 Posts

Posted - 2002-07-16 : 05:02:18
I created a new table with a varchar(10) field and CHARACTER_MAXIMUM_LENGTH gave 10 with no data in the table.
try

create table test (s varchar(10))
go
select * from information_schema.columns where table_name = 'test'

What version / service pack are you running on?
You could also try the length field of syscolumns but I suspect that is the same field.

==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Utpal
Posting Yak Master

179 Posts

Posted - 2002-07-17 : 04:23:09
Thanks nr ! CHARACTER_MAXIMUM_LENGTH works. Actually I was looking at the numeric fields whose CHARACTER_MAXIMUM_LENGTHs are shown as NULL.


Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-07-17 : 07:56:02
FYI you could also try the COL_LENGTH function:

SELECT COL_LENGTH ('myTable', 'myColumn')

Go to Top of Page
   

- Advertisement -