回覆列表
  • 1 # 使用者5189701024573

    測試透過,那是相當的順利

    --exec add_column "net_code","dddr",""

    create proc add_column

    @table varchar(100),--表名

    @columns varchar(100),--欄位名

    @type varchar(100)--資料型別(如不設定,預設為varchar(100))

    as

    declare @sql varchar(3000),@type_code varchar(100)

    if @type=""

    begin

    set @type_code="varchar(100)"

    end

    set @sql="if NOT EXISTS (select a.Name as columnName

    from syscolumns as a

    , sysobjects as b where a.ID=b.ID

    and b.Name="""+@table+"""

    and a.name="""+@columns+""")

    BEGIN

    alter table "+@table+" add "+@columns+" "+@type_code+"

    select a.Name as columnName

    from syscolumns as a

    , sysobjects as b where a.ID=b.ID

    and b.Name="""+@table+"""

    END

    ELSE

    BEGIN

    PRINT ""欄位已經存在!""

    END

    "

    --print @sql

    exec(@sql)

  • 中秋節和大豐收的關聯?
  • 關於感恩的名言警句?