create   table   #staff   (id   int)  
  insert   into   #staff   values(9)  
  if   exists(select   1   from   #staff   where   id=9)  
          print('pass')  
  else  
          print('fail')  
  drop   table   #staff  
   
  把where   id=9的值改成其它的值就输出fail,其它就可自己体会理解了  

 

1不是临时表#class的字段,而是用来判断查询是否为空的标记

----------------------------------

判断表存在:

if not object_id('表名') is null

      drop table 表名

以前常用IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = '表名'

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[forums_User_CreateUpdateDelete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[forums_User_CreateUpdateDelete]

posted on 2009-06-19 04:52  阿C's  阅读(1860)  评论(0编辑  收藏  举报