许松--永恒学习屋
努力并不一定会成功,但放弃一定会失败!


--循环在表中增加列
SET NOCOUNT ON

DECLARE  @barcode_head varchar(10)
declare @sql varchar(500)

--声明游标
DECLARE business_cursor CURSOR FOR
SELECT barcode_head FROM s_business order by id

OPEN business_cursor
FETCH NEXT FROM business_cursor INTO @barcode_head


WHILE @@FETCH_STATUS = 0
BEGIN
   PRINT @barcode_head
   set @sql='alter table db_'+@barcode_head+'_user add Trans_startTime datetime'
   exec(@sql)
   print @sql
   FETCH NEXT FROM business_cursor INTO @barcode_head
  
end
close business_cursor

DEALLOCATE business_cursor
GO

posted on 2011-12-28 11:54  yongheng's blogs  阅读(541)  评论(0编辑  收藏  举报