-_-! if object_id('##temp') is not null drop table ##temp
IF EXISTS (SELECT * FROM SYSOBJECTS WHERE NAME='#temp') DROP TABLE #temp
-_-! USE tempdb GO if object_id('##temp') is not null drop table ##temp
你要这个啊,理解错了。 参考:LS的基本都是对的: if object_id('##temp') is not null drop table ##temp
谢谢flytigerme的这个问题,之前没注意。 9F为方式一。方式二:--生成全局临时表 select * into ##cl from sys.databases--判断并删除 if object_id(N'tempdb..##cl') is not null drop table ##cl--再次查询 select * from ##cl/* 消息 208,级别 16,状态 0,第 1 行 对象名 '##cl' 无效。 */
这个是删除实体表的、零时表用的是 if object_id(N'tempdb..##cl') is not null drop table ##cl
if object_id(N'Gps..##temp') is not null drop table ##temp select identity(int) id0,* into ##temp from NowXcDataTest这样去执行,但是还是提示 消息 2714,级别 16,状态 6,第 6 行 数据库中已存在名为 '##temp' 的对象。 该怎么弄?
USE Gps GO if object_id('##temp') is not null drop table ##temp select identity(int) id0,* into ##temp from NowXcDataTest这个才是 数据库中已存在名为 '##temp' 的对象。这个怎么改?
if object_id(N'tempdb..##temp') is not null drop table ##temp select identity(int) id0,* into ##temp from NowXcDataTest
USE Test GOIF OBJECT_ID('NowXcDataTest') IS NOT NULL DROP TABLE NowXcDataTest GOCREATE TABLE NowXcDataTest ( test1 INT , test2 VARCHAR(20) ) INSERT INTO NowXcDataTest ( test1 , test2 ) SELECT 1 , 'test1' UNION ALL SELECT 2 , 'test2'SELECT * FROM NowXcDataTest IF OBJECT_ID('tempdb..##temp') IS NOT NULL DROP TABLE ##temp GOSELECT IDENTITY( INT ) id0 , * INTO ##temp FROM NowXcDataTestSELECT * FROM ##temp
看样子楼主和我一样,是初学者,呵呵if object_id('[tb]') is not null drop table [tb]
====
两个##的是全局临时表,一个#的是当前对话范围内有效。删除还是一样
drop table ##temp不过要保证##tmp全局表都没有用户访问,否则失败。
我就是想问那if exists(..) drop table
然后再建,怎么写?
if object_id('##temp') is not null
drop table ##temp
IF EXISTS (SELECT * FROM SYSOBJECTS WHERE NAME='#temp')
DROP TABLE #temp
USE tempdb
GO
if object_id('##temp') is not null
drop table ##temp
参考:LS的基本都是对的:
if object_id('##temp') is not null
drop table ##temp
9F为方式一。方式二:--生成全局临时表
select *
into ##cl
from sys.databases--判断并删除
if object_id(N'tempdb..##cl') is not null
drop table ##cl--再次查询
select * from ##cl/*
消息 208,级别 16,状态 0,第 1 行
对象名 '##cl' 无效。
*/
if object_id(N'tempdb..##cl') is not null
drop table ##cl
http://blog.csdn.net/claro/archive/2010/02/22/5316129.aspx
drop table ##temp
select identity(int) id0,* into ##temp from NowXcDataTest这样去执行,但是还是提示
消息 2714,级别 16,状态 6,第 6 行
数据库中已存在名为 '##temp' 的对象。
该怎么弄?
GO
if object_id('##temp') is not null
drop table ##temp
select identity(int) id0,* into ##temp from NowXcDataTest这个才是
数据库中已存在名为 '##temp' 的对象。这个怎么改?
drop table ##temp
select identity(int) id0,* into ##temp from NowXcDataTest
GOIF OBJECT_ID('NowXcDataTest') IS NOT NULL
DROP TABLE NowXcDataTest
GOCREATE TABLE NowXcDataTest
(
test1 INT ,
test2 VARCHAR(20)
)
INSERT INTO NowXcDataTest
( test1 ,
test2
)
SELECT 1 ,
'test1'
UNION ALL
SELECT 2 ,
'test2'SELECT *
FROM NowXcDataTest
IF OBJECT_ID('tempdb..##temp') IS NOT NULL
DROP TABLE ##temp
GOSELECT IDENTITY( INT ) id0 ,
*
INTO ##temp
FROM NowXcDataTestSELECT *
FROM ##temp