Sql语句执行效率问题,走过路过都进来看看!(exists,count,值类型,单引号)
Sql语句的效率问题,大家帮忙看看: 
 (以下问题皆为程序中直接使用Sql语句,非存储过程) 
 设表   [Table1]   字段为: 
 [ID]   int 
 [A]      varchar(50) 
 [B]      bit 
 [C]      int 
 [D]      datetime   
 1、Sql语句执行过程中如何绑定变量(?内部类型转换?): 
 Sql语句中的变量值是否都是作为   字符串   类型   强行转换成   内部类型的? 
 下面两条语句有什么区别?执行效率上呢(会不会有额外的消耗)? 
 select   *   from   [Table1]   where   [ID]   =   10 
 select   *   from   [Table1]   where   [ID]   =    '10 ' 
 如果是   insert或update   呢?既然“单引号”是“边界符”,是否所有能格式化成字符串的   sql语句里的   变量的   值   都可以加上单引号呢? 
 如:(下面的语句执行效率有区别吗?是不是所有的值都可以加上单引号?) 
 insert   into   [Table1]   values   ( 'a ',   0,   1,    '2007-01-01 ') 
 insert   into   [Table1]   values   ( 'a ',    '0 ',    '1 ',    '2007-01-01 ')   
 2、使用Sql语句查询“数据是否已存在”: 
 怎么写效率最高? 
 select   1   where   exists   (select   [ID]   from   Table1   where   [ID]=1001) 
 select   count(1)   from   Table1   where   [ID]   =   1001 
 select   count([ID])   from   Table1   where   [ID]   =   1001 
 select   [ID]   from   Table1   where   [ID]   =   1001 
 select   top   1   [ID]   from   Table1   where   [ID]   =   1001     
------解决方案--------------------select * from [Table1] where [ID] = 10 
 select * from [Table1] where [ID] =  '10 ' 
 ------------------ 
 這個當然上面的好了,下面的要轉換成int 
------解决方案--------------------下面两条语句有什么区别?执行效率上呢(会不会有额外的消耗)? 
 select * from [Table1] where [ID] = 10 
 select * from [Table1] where [ID] =  '10 ' 
 --------------------- 
 一样,可以看执行计划     
------解决方案--------------------  如果ID唯一,不要加top 1,top 1比较影响性能,有top就会做一次sort. 如果id是主键,即使有top 1 也没有关系。   
 有count 肯定慢的,要先进行group by,   
 如果ID重复记录非常多,感觉用exists 就应该会快点