if exists (select 1 from sysobjects where type='u' and name =tablename)
begin
    alter table tablename add columnname columntype
end
else
begin
    create table tablename (col1 int identity(1,1)...)
end

解决方案 »

  1.   

    if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
          begin
             create table 表名(ID int identity(1,1),....)
          end
    else
          begin
             alter table 表名 add 字段1 类型1,字段2 类型2....
          end
      

  2.   

    if exists (select * from sysobjects where name =tablename)
    begin
        alter table tablename add 字段1 类型1,字段2 类型2....
    end
    else
    begin
        create table tablename (col1 int identity(1,1)...)
    end