Home > Database > Mysql Tutorial > SQL Server 临时表的删除

SQL Server 临时表的删除

WBOY
Release: 2016-06-07 14:55:21
Original
1602 people have browsed it

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 --错误的临时表删除操作,因为

  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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template