判断MSSQL表/存储过程/视图是否存在

1).判断用户表是否存在

if exists (select top 1 * from sysobjects where id = object_id(N'[所有者.]表名') and type='U')

2).判断临时表是否存在

if object_id('tempdb..##temp') is not null

3).判断存储过程是否存在

if exists (select top 1 * from sysobjects where id=object_id('[所有者.]存储过程名') and type='P')

4).判断视图是否存在

if exists (select top 1 * from sysobjects where id=object_id('[所有者.]视图名') and type='V')


评论: 0 | 引用: 0 | 查看次数: 5904
发表评论
登录后再发表评论!