Sql Server 批量清理表数据--sql语句实现

277 阅读1分钟

批量清理表数据

     declare @tablecolumnname varchar(100) 
     declare cursor1 cursor for         
    Select Name FROM esldatamanager..SysObjects Where XType='U' orDER BY Name   
      open cursor1                       
     fetch next from cursor1 into @tablecolumnname 
     while @@fetch_status=0           
     begin
         set @sql='truncate table  '+@tablecolumnname --清理表语句
         print @sql 
         exec(@sql)             
         fetch next from cursor1 into @tablecolumnname 
     end
     close cursor1                   
     deallocate cursor1