首页 > 网站 > 建站经验 > 正文

SQL S、erver 临时表的删除

2019-11-02 14:53:00
字体:
来源:转载
供稿:网友
八个字网名[www.la240.com/html2017/1/8/]

   1、错误的删除操作:

  --错误的临时表删除操作,因为所在数据库不同

  IF EXISTS (SELECT * FROM sysobjects WHERE object_id = OBJECT_ID(N'[dbo].[#tempTable]') AND type in (N'U'))

  Begin

  DROP TABLE [dbo].[tempTable]

  End

  --错误的临时表删除操作,因为临时表名已变

  if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'[#temptable]'))

  Begin

  drop table #temptable

  End

  2、正确的删除方式:

  --正确的临时表删除操作

  if object_id('tempdb#tempTable') is not null Begin

  drop table #tempTable

  End

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表