日期:2014-05-17  浏览次数:20424 次

查询数据库中含有某一数据类型列的表名
比如说我想查询我数据库中所有列类型为text的列名和所对应的表
求帮忙

------解决方案--------------------
SQL code

  Select C.NAME As ObjName, A.Name As FldName, B.Name As TypeName, A.Length 
  From SYSCOLUMNS A Inner Join SYSTYPES B On A.xtype = B.xtype
                    Inner Join SYSOBJECTS C ON A.ID = C.ID
  Where C.xtype = 'U' And B.Name = 'Text'

------解决方案--------------------
SQL code


select b.name as Tab,a.name as Col,a.max_length as Len from sys.columns a inner join sys.tables b on a.object_id = b.object_id
inner join sys.types c on a.system_type_id = c.system_type_id and c.name <>'sysname'
where c.name = 'text'

------解决方案--------------------
SQL code
SELECT OBJECT_NAME([object_id]) AS table_name ,name AS column_name
FROM sys.columns 
WHERE system_type_id=TYPE_ID('text')