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

posted @ 2020-10-23 15:35  筱老邪  阅读(308)  评论(0编辑  收藏  举报