If Object_id('Template') Is Not Null
Alter Table Template
Add [UserID] varchar(1000) NULL,
Add [ProtypeTemplateID] uniqueidentifier NULL;sql server 2005
我要给template表加2个字段,老是提示错误
消息 156,级别 15,状态 1,第 4 行
关键字 'Add' 附近有语法错误。

解决方案 »

  1.   

    If Object_id('Template') Is Not Null 
    Alter Table Template 
    Add [UserID] varchar(1000) NULL
    ALTER TABLE TEMPLATE
    Add [ProtypeTemplateID] uniqueidentifier NULL; 
      

  2.   

    If Object_id('Template') Is Not Null 
    Alter Table Template 
    Add [UserID] varchar(1000) NULL, [ProtypeTemplateID] uniqueidentifier NULL; 
      

  3.   

    Alter Table table1 
    Add [UserID] varchar(1000) NULL 
    Alter Table table1 
    Add [ProtypeTemplateID] uniqueidentifier NULL
      

  4.   

    可以合并,但只用一个 add:If Object_id('Template') Is Not Null 
    Alter Table Template 
    Add [UserID] varchar(1000) NULL, 
        [ProtypeTemplateID] uniqueidentifier NULL; 
      

  5.   

    If Object_id('Template') Is Not Null 
    Begin
    Alter Table Template 
    Add [UserID] varchar(1000) NULL, 
        [ProtypeTemplateID] uniqueidentifier NULL; 
    End
    比较安全