create database TabTest go use TabTest go create table tableTest ( file1 varchar(10) ) go select * from tableTest begin declare @count int,@strSQL varchar(100) set @count=2 BEGIN TRANSACTION--开始事务 DECLARE @errorSun INT --定义错误计数器 SET @errorSun=0 --没错为0 while @count<1026 begin set @strSQL='ALTER TABLE tableTest ADD file'+cast(@count as varchar(20))+' varchar(10)' exec(@strSQL) SET @errorSun=@errorSun+@@ERROR --累计是否有错 set @count=@count+1 end IF @errorSun<>0 BEGIN PRINT '有错误,回滚 列号'+@count ROLLBACK TRANSACTION--事务回滚语句 END ELSE BEGIN PRINT '成功,提交' COMMIT TRANSACTION--事务提交语句 END end