Sql server 简单查询出错

Sql server 简单查询出错,sql-server,tsql,Sql Server,Tsql,我一定是休息了一天。这应该是显而易见的,但我不明白 -- check for necessary updates to dbnotes select count(distinct table_name) from ccsv4.[INFORMATION_SCHEMA].[COLUMNS] 返回46 select count(distinct table_name) from dbnotes 返回44 select distinct table_name from ccsv4.[INFOR

我一定是休息了一天。这应该是显而易见的,但我不明白

-- check for necessary updates to dbnotes
select count(distinct table_name) 
from ccsv4.[INFORMATION_SCHEMA].[COLUMNS]
返回46

select count(distinct table_name) 
from dbnotes
返回44

select distinct table_name 
from ccsv4.[INFORMATION_SCHEMA].[COLUMNS]
where table_name not in (select distinct table_name from dbnotes)
order by table_name
一无所获

select distinct table_name 
from dbnotes
where  table_name not in (select distinct table_name 
                          from ccsv4.[INFORMATION_SCHEMA].[COLUMNS])
order by table_name
一无所获

select distinct table_name 
from dbnotes
where  table_name not in (select distinct table_name 
                          from ccsv4.[INFORMATION_SCHEMA].[COLUMNS])
order by table_name

我错过了什么?你们使用的是
而不是
。如果子查询中的任何值为
NULL
,则不会返回任何内容

对于子查询,始终使用
不存在
。它具有正确的语义:

select distinct table_name
from ccsv4.[INFORMATION_SCHEMA].[COLUMNS] c
where not exists (select 1
                  from dbnotes d
                  where d.table_name = c.table_name 
                 );
我非常确定表必须至少有一列,因此您最好使用
信息\u schema.tables
。它将为您保存不同的

select table_name
from ccsv4.information_schema.tables t
where not exists (select 1
                  from dbnotes d
                  where d.table_name = t.table_name 
                 );

什么是
dbnotes
和这个结构?什么是
ccsv4
?如果看不到前两个查询的数据(没有区别),我们(或您)如何知道它们重叠?请发布示例数据和/或schemaThanks。对于那些提问的人来说,CCSv4是数据库,DBNotes是表。此外,数据库中有46个列名,notes表中有44个列名。我正在使用notes表来记录数据库的表。重叠部分是notes表中已经存在的所有44个列名(行)。我希望在从dbnotes中没有的模式信息中选择时返回2行。我将尝试不同的语法建议。