sql 语句查询数据库是否存在该表

c282174871c 2010-06-07 04:21:13
已知表名 table1
有该表显示表名 无则为空
...全文
344 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
shixixi1987 2010-06-07
  • 打赏
  • 举报
回复
use 数据库名
go
if exists(select * from sysobjects where [name]='表名')
drop table 表名
go
wqmgxj 2010-06-07
  • 打赏
  • 举报
回复

if(Exists(select 1 from sysobjects where name='tablename'and type='U')) print '存在'
else print '不存在'
feilniu 2010-06-07
  • 打赏
  • 举报
回复

DECLARE @TableName nvarchar(100)
SET @TableName = 'table1'
SELECT CASE WHEN OBJECT_ID(@TableName) IS NOT NULL THEN @TableName END
htl258_Tony 2010-06-07
  • 打赏
  • 举报
回复
SELECT CASE WHEN OBJECT_ID('table1')>0 THEN '存在table1' END
/*
----------
存在table1

(1 行受影响)
*/

SELECT CASE WHEN OBJECT_ID('table12121')>0 THEN '存在table1' END
/*
----------
NULL

(1 行受影响)
*/
xuam 2010-06-07
  • 打赏
  • 举报
回复
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[table1]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
htl258_Tony 2010-06-07
  • 打赏
  • 举报
回复
select case when object_id('table1')>0 then '存在table1' else '不存在table1' end
jwdream2008 2010-06-07
  • 打赏
  • 举报
回复
if object_id('table1   ') is not null
print 'table1 '
水族杰纶 2010-06-07
  • 打赏
  • 举报
回复
if object_id('table1','U')is not null
print 'table1'
else
print NUll
nianran520 2010-06-07
  • 打赏
  • 举报
回复
if object_id('table1','U') is not null
print '有'
else
print '无'

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧