漫漫技术人生路

C#

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

create Table #tempTable
(
   ID int IDENTITY PRIMARY KEY,
   bookId int,
   bookName varchar(50)
)
go
declare @a int
set @a=(select   count(*) as 'aa'  from   sysobjects   where   name = '#tempTable')
select @a as 'aaaaaa'
结果为了,临时表是始终为0的

在SQL中判断一个表是否存在 

<%sql="if exists (select * from sysobjects where id = object_id(N'[dbo].[phone]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[phone]"
con.execute(sql)
%>
如果表phone存在则删除phone表
其中phone是表名,con是connection对像 

 

<br/>

<hr>

对一个表导出其脚本,里面有例子

<br/>

<hr>

SELECT   count(*)   <br/>   FROM   sysobjects   <br/>   WHERE   name   =   'jqwm'

<br/>

<hr>

   <br/>   SELECT   count(*)   <br/>   FROM   sysobjects   <br/>   WHERE   name   =   'yourtablename'         <br/>      <br/>     

<br/>

<hr>

select   count(*)   from   sysobjects   where   name   =   &quot;tablename'   and   type   ='U'   <br/>   count(*)&gt;=1表示存在

<br/>

<hr>

select   count(*)   from   sysobjects   where   name   =   &quot;tablename'   and   type   ='U'   <br/>   count(*)&gt;=1表示存在   <br/>   或者如IronPromises(铁诺) 的方法,本质上一回事

<br/>

<hr>

同意楼上的   <br/> 


SELECT Count(*) AS Qty
            FROM MSysObjects
            WHERE (((MSysObjects.Name) Like 需判断的已知表名));

posted on 2006-09-27 16:38  javaca88  阅读(811)  评论(0编辑  收藏  举报