sql 查詢出符合條件的表增加字段

--ImplusDb數據庫

use [ImplusDb]
go

declare @name varchar(50);
declare @STMT nvarchar(max)         -- SQL to execute
declare cur_data SCROLL cursor for
select distinct(name) from sysobjects where xtype='U' and name like 'ChatHistory%' and name <> 'ChatHistoryManage';
open cur_data
fetch next from cur_data into @name
    while(@@fetch_status=0)
    begin
        SET @STMT =  'alter table '+@name+' add  UserToken  varchar(50) not null default ('''');'   
            EXEC (@STMT)  
        fetch next from cur_data into @name
    end;
    close cur_data    
    DEALLOCATE cur_data

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章