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 |
|
dstalker
Starting Member
2 Posts |
Posted - 2005-08-23 : 10:09:04
|
| I want to create a select statement that will return to me useful information for a table. This info would include table name, column name, column type, column length, Max string length in column. The SQL statement I have so far errors on the Max string length.select o.name as TableName, c.name as ColName, u.name as ColType, c.length as ColLen, (select max(LEN(LTRIM(RTRIM(c.name)))) from o.name) as maxlenfrom sysobjects o inner join syscolumns c on o.id = c.idinner join systypes u on c.xtype = u.xtypewhere o.name='TableName' group by o.name, c.name,u.name,c.length,c.colorderorder by c.colorderThanks. Dwayne |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-23 : 10:23:42
|
| select * from information_schema.columnswhere table_name='tt' order by ordinal_positionMadhivananFailing to plan is Planning to fail |
 |
|
|
dstalker
Starting Member
2 Posts |
Posted - 2005-08-23 : 11:10:59
|
| Thanks for the response.Maybe I should have said 'longest' instead of MAX. I want to change some column data types from Char(500) to Varchar(?), and I do not want to truncate any useful data, so I am curious if I can get all this in one SQL statement. This table does not seem to give me the actual string length i.e. (LTRIM(RTRIM(c.name)) Thanks. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-24 : 00:59:37
|
| If you want to change from Char to varchar use the same column widthThis will show you the maximum lengths of each columnselect column_name,Data_type,Character_maximum_length from information_schema.columnswhere table_name='tableName' order by ordinal_positionTo know the maximum characters in the tableselect name,length from syscolumns where id=object_id('tableName')order by colidMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|