SQL贴出来
 要不看不明白

解决方案 »

  1.   


    create proc proc_addtable
    as
    if exists(select * from sysobjects where id=object_id('newtable') and xtype='u')
         drop table newtable
    else
    create table newtable (i int,ii datetime)
    select * from newtable
    --run
    exec proc_addtable
      

  2.   

    回: aierong(皑婀瑢-数据库XML.NET联盟会科长):
      如你所写我执行了exec proc_addtable 
      但是查询分析器提示:
      服务器: 消息 208,级别 16,状态 1,过程 proc_addtable,行 7
       对象名 'newtable' 无效。 我自己也看了在该存储过程所属的数据库中找不到该表。
      

  3.   

    IF EXISTS (SELECT 1 FROM SYSOBJECTS WHERE ID = OBJECT_ID(N'proc_addtable') AND OBJECTPROPERTY(ID,N'ISprocedure') = 1)
    DROP procedure proc_addtablego
    create proc proc_addtable
    as
    if exists(select * from sysobjects where id=object_id('newtable') AND OBJECTPROPERTY(ID,N'IsUserTable') = 1)
         drop table newtable
    else
    create table newtable (i int,ii datetime)
    select * from newtable
    drop table newtable--增加这句话就可以了
    go
    exec proc_addtable--如果不增加这句话的话,第一次执行是可以的,第二次就不成了,间隔性的成功
      

  4.   

    --存储过程中有问题,做如下修改
    create proc proc_addtable
    as
    if exists(select * from sysobjects where id=object_id('newtable') and xtype='u')
    begin
         drop table newtable
    end 
    create table newtable (i int,ii datetime)
    select * from newtable
      

  5.   

    除非你创建的是临时表,否则是可以保存的.例子:
    create proc p_test
    as
    if not exists(select 1 from syscolumns where object_id('tb')=id
      create table tb(id int)
    go--测试
    exec p_test
    select * from tb