显示存在两列的所有表 - SQL Server 2008

时间:2016-03-01 00:59:16

标签: sql-server search where

我想搜索包含'Documentversionid'和'ClientMedicationID'列的所有表。

2 个答案:

答案 0 :(得分:0)

试试这个:

SELECT t1.TABLE_NAME
FROM
(
    SELECT TABLE_NAME 
    FROM INFORMATION_SCHEMA.COLUMNS 
    WHERE COLUMN_NAME LIKE '%Documentversionid%'
) t1
INNER JOIN
(
    SELECT TABLE_NAME 
    FROM INFORMATION_SCHEMA.COLUMNS 
    WHERE COLUMN_NAME LIKE '%ClientMedicationID%'
) t2
    ON t1.TABLE_NAME = t2.TABLE_NAME

答案 1 :(得分:0)

这应该这样做:

SELECT COUNT(*) as COUNT, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME  
FROM `information_schema`.`columns` 
WHERE `TABLE_SCHEMA`='<YOUR DATABASE>' AND 
   (`COLUMN_NAME` = 'Documentversionid' OR `COLUMN_NAME`='ClientMedicationID') 
GROUP BY `TABLE_NAME` HAVING COUNT > 1