不包含某些字段的视图列表

时间:2015-02-23 21:23:33

标签: sql-server sql-server-2000

我知道获取数据库中所有视图列表的语法,但是我怎么能翻转它以显示所有不包含字段的视图的列表?例如,我想看到所有不包含字段Salutation的视图,我该怎么做? 这将是我用来获取数据库中所有视图列表的语法:

SET NOCOUNT ON;

CREATE TABLE T
  (
     ID INT IDENTITY NOT NULL,
     VN VARCHAR(1000)
  );

INSERT INTO T
            (VN)
SELECT '[' + C.Table_Catalog + '].[' + C.Table_Schema + '].[' + C.Table_Name + ']' VN
FROM   Information_Schema.Columns C
       JOIN Information_Schema.Tables T
         ON C.Table_Catalog = T.Table_Catalog
            AND C.Table_Schema = T.Table_Schema
            AND C.Table_Name = T.Table_Name
WHERE  T.Table_Type = 'View'
GROUP  BY '[' + C.Table_Catalog + '].[' + C.Table_Schema + '].[' + C.Table_Name + ']'; 

1 个答案:

答案 0 :(得分:3)

SELECT QUOTENAME(v.TABLE_CATALOG) + '.'
       + QUOTENAME(v.TABLE_SCHEMA) + '.'
       + QUOTENAME(v.TABLE_NAME)
FROM   INFORMATION_SCHEMA.TABLES v
WHERE  NOT EXISTS (SELECT 1
                   FROM   INFORMATION_SCHEMA.COLUMNS ic
                   WHERE  ic.TABLE_NAME = v.TABLE_NAME
                          AND ic.TABLE_SCHEMA = v.TABLE_SCHEMA
                          AND ic.COLUMN_NAME = 'Salutation')
       AND v.TABLE_TYPE = 'VIEW'