select identity(int) id0,* into ##temp from NowXcDataTest第一次建了之后就不能再建了,想问问多次重建If exists怎么写

解决方案 »

  1.   

    ##temp
    ====
    两个##的是全局临时表,一个#的是当前对话范围内有效。删除还是一样
    drop table ##temp不过要保证##tmp全局表都没有用户访问,否则失败。
      

  2.   

    多次重建?那你得先drop原来的才行。
      

  3.   


    我就是想问那if exists(..) drop table
    然后再建,怎么写? 
      

  4.   

    if object_id('[tb]') is not null drop table [tb]
      

  5.   

    http://blog.csdn.net/claro/archive/2010/02/22/5316129.aspx
      

  6.   

    if object_id('##temp') is not nulldrop table #a
      

  7.   

    -_-!
    if object_id('##temp') is not null 
    drop table ##temp
      

  8.   


    IF  EXISTS (SELECT * FROM SYSOBJECTS WHERE NAME='#temp')
      DROP TABLE #temp
      

  9.   

    -_-! 
    USE tempdb
    GO
    if object_id('##temp') is not null  
    drop table ##temp
      

  10.   

    你要这个啊,理解错了。
    参考:LS的基本都是对的:
    if object_id('##temp') is not null
    drop table ##temp
      

  11.   

    谢谢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' 无效。
    */
      

  12.   

    这个是删除实体表的、零时表用的是
    if object_id(N'tempdb..##cl') is not null  
    drop table ##cl
      

  13.   

    已更新博文
    http://blog.csdn.net/claro/archive/2010/02/22/5316129.aspx
      

  14.   

    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' 的对象。
    该怎么弄?
      

  15.   

    USE Gps
    GO
    if object_id('##temp') is not null  
    drop table ##temp
    select identity(int) id0,* into ##temp from NowXcDataTest这个才是
    数据库中已存在名为 '##temp' 的对象。这个怎么改?
      

  16.   

    if object_id(N'tempdb..##temp') is not null  
    drop table ##temp
    select identity(int) id0,* into ##temp from NowXcDataTest
      

  17.   

    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
      

  18.   

    看样子楼主和我一样,是初学者,呵呵if object_id('[tb]') is not null drop table [tb]