加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

判断表(临时表),存储过程是否存在

发布时间:2020-12-12 12:46:45 所属栏目:MsSql教程 来源:网络整理
导读:1.判断 正式 表或者存储过程是否存在 ? select * from? dbo.sysobjects ?where id=OBJECT_ID(N'dbo.Users') and? type='U' ? --U表示表 ? ?select * from? dbo.sysobjects ?where id= object_id(N'usp_InsertAliPayFeedback') and? type='P' ?--P表示存储过
1.判断 正式表或者存储过程是否存在 ? select * from? dbo.sysobjects?where id=OBJECT_ID(N'dbo.Users') and? type='U' ? --U表示表
? ?select * from? dbo.sysobjects?where id= object_id(N'usp_InsertAliPayFeedback') and? type='P' ?--P表示存储过程
2.判断 临时表类型 ? select * from? tempdb.dbo.sysobjects?where id= OBJECT_ID(N'tempdb.dbo.#tempa') and? type='U' ? --U表示表
???select * from? tempdb.dbo.sysobjects?where id= OBJECT_ID(N'usp_InsertAliPayFeedback') and? type='P' ?--P表示存储过程
?对象类型。可以是下列值之一:?
?C = CHECK 约束 ? D = 默认值或 DEFAULT 约束 F = FOREIGN KEY 约束?
?FN = 标量函数 IF = 内嵌表函数 ?K = PRIMARY KEY 或 UNIQUE 约束?
?L = 日志? P = 存储过程 ?R = 规则 ?RF = 复制筛选存储过程?
?S = 系统表 ?TF = 表函数 TR = 触发器? U = 用户表 V = 视图 ?X = 扩展存储过程
举个小例子: ?if exists(select * from tempdb.dbo.sysobjects where id= OBJECT_ID(N'tempdb.dbo.#tempa')) ?--是否存在该临时表 ?drop table #tempa ? ?--存在则删除 create table #tempa ( ?Num int, ?Name varchar(20) default '名字' ? --列的默认值设置 ) ?declare @a int ?set @a = 1 ?while @a<30 ?begin ? insert into #tempa (Num) values (@a) ?set @a = @a+1 ?end select * from #tempa

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读