【sqlserver】那些令你一脸懵逼的执行结果

来源:互联网 发布:windows查看cpu温度 编辑:程序博客网 时间:2024/06/09 13:58
--IN失效问题create table ta (id int,val varchar(10))create table tb (di int, --注意不是IDval varchar(10))insert into ta values(1,'x'),(2,'y')insert into tb values(1,'x')SET STATISTICS PROFILE ON --执行计划(文本)select val from ta where id in (select id from tb);--逻辑:in中select的字段优先在in中的from表中寻找,若找不到则在in外的表中寻找/*--执行计划  |--Nested Loops(Left Semi Join)       |--Table Scan(OBJECT:([datayesdb].[dbo].[ta]), WHERE:([datayesdb].[dbo].[ta].[id]=[datayesdb].[dbo].[ta].[id]))       |--Table Scan(OBJECT:([datayesdb].[dbo].[tb]))--结果xy*/--drop table tb;  drop table ta;------------------------------------------NULL导致失效--注意NULL和任何值的计算结果都是NULL,可能为空的字段一定要做处理,否则可能出现预料之外的结果
0 0
原创粉丝点击