SQL SERVER批处理在多张表中加同一个字段脚本

select ID_Num = IDENTITY(int, 1, 1),name into #tempt from sysobjects where xtype = 'U' and name like 'ESC_%' and status >=0
select * from #tempt

declare @id int
set @id = 1
DECLARE @STRING VARCHAR(8000)
WHILE(@id < 189)
BEGIN
SELECT @STRING='ALTER TABLE '+name  FROM   #tempt where ID_Num = @id
SET @STRING = @STRING + ' ADD TimeStamp timestamp null'
 --SELECT @STRING
 EXEC(@STRING)
select @id = @id +1
END

GO

你可能感兴趣的:(SQL Server)