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.
| 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.trycreate table test (s varchar(10))goselect * 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. |
 |
|
|
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. |
 |
|
|
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') |
 |
|
|
|
|
|