2011-06-03 78 views

回答

6

試試這個:

SELECT a.name -- OR a.* 
    FROM syscolumns a INNER JOIN systypes b 
    ON a.xtype = b.xtype 
    AND b.name = 'ntext' -- OR OTHER DATA TYPE. 
+0

這是完美的,我需要找到的除了我需要知道表的列被發現英寸我如何修改此以包括表名? – HPWD 2012-05-31 14:49:37

+1

不知道這是否是最好的方式,但這對我來說非常合適。 'SELECT a.name,o.name AS TableName,o.type,a.id,o.object_id,o.schema_id FROM sys.syscolumns AS INNER JOIN sys.systypes AS b ON a.xtype = b.xtype AND b.name ='char'AND a.length = 6 INNER JOIN sys.objects AS o ON a.id = o.object_id WHERE(o.type ='u')AND(o.schema_id = 1)' – HPWD 2012-05-31 15:14:24

+0

適合新來者。 @dlackey的評論可能不適合你。這是因爲還原劑長度限制。用這個代替:'SELECT a.name,o.name AS TableName,o.type,a.id,o.object_id,o.schema_id,a.length FROM sys.syscolumns AS a INNER JOIN sys.systypes AS b ON a.xtype = b.xtype AND b.name ='YOUR_DATA_TYPE' INNER JOIN sys.objects AS o ON a.id = o.object_id WHERE(o.type ='u') AND(o。 schema_id = 1)' – duleshi 2015-01-30 02:01:40

2

試試這個

SELECT o.name AS 'Table Name', c.name AS 'Column Name' FROM sysobjects AS o 
INNER JOIN syscolumns AS c ON o.name = c.object_id 
INNER JOIN systypes AS t ON t.xtype = c.xtype 
WHERE b.name = ' ntext' 

希望這有助於。

+0

無法找到b.name的這個錯誤,因爲沒有b的別名 – kevchadders 2015-04-16 14:09:21

1
SELECT so.name, sc.name 
    FROM sys.objects so 
    JOIN sys.columns sc ON so.object_id = sc.object_id 
    JOIN sys.types stp ON sc.user_type_id = stp.user_type_id 
        AND stp.name = 'ntext' 
WHERE so.type = 'U' -- to show only user tables 
1

我知道這個問題已經被回答了,但是我想把表名添加到結果集中,這個查詢就是這麼做的。

SELECT a.name, o.name AS TableName, o.type, a.id, o.object_id, o.schema_id 
FROM sys.syscolumns AS a INNER JOIN sys.systypes AS b ON a.xtype = b.xtype 
AND b.name = 'char' 
AND a.length = 6 INNER JOIN 
sys.objects AS o ON a.id = o.object_id 
WHERE (o.type = 'u') 
AND (o.schema_id = 1) 
相關問題