mssql 容易掉进的坑

 

1.     重复 使用 into #tabel(不是在开头使用insert into ) 会报错   if  1=1 begin  select *

into #tabel from productoin

end else begin

 select * into #tabel from productoin

end

 

2.  select top 100  cus ,*     from  mytable   order by cus   --  这样会出现异常  因为出现两列  cus  ,无法判断具体是那一列排序

 --    正确 :  order by cus  修改为 order by  mytable.cus

3.   select top 100  cus , name ,tech   from  mytable    group   by cus  --出错   正确应该为:   group   by  cus , name ,tech

4. 在存储过程中这样写

if  @df='N' begin

end   -- begin  end 内部没有任何内容, 空着 会出错 (加上 ; 也是) 最好注释掉 或者  内容添加  -- 修正后为 也可以: if  @df='N' begin select '' end

5 . 调用有参数的存储过程 参数 不应该有  括号   方法  应该有 括号 ,方法返回的时候是 returns 不是return  .调用的时候应该有dbo.functionname   --注意一定要有dbo. 

6.  insert into  #t select  a,b,c from tablename    和     select a,b,c  into #t  from tablename       使用  insert into  #t select   需要事先声明 create table #t         select a,b,c  into #t   为系统自动创建   

posted @ 2014-12-04 10:57  孜然道  阅读(139)  评论(0编辑  收藏  举报