清除指定數據庫各個表中所有的記錄

 ---- 清除指定數據庫各個表中所有的記錄

  use   database   ---打開指定的數據庫名
  declare   @name   varchar(140)  
  declare deletecursor cursor  for   select   name   from   datebawse.dbo.sysobjects   where   xtype='U' ---U是得到所有的用戶建立的表 
  open   deletecursor  
  fetch   next   from   ##cursor   into   @name  

  while   @@fetch_status=0   --執行到最後
  begin

    ---exec('select '+@name)   

      exec('truncate   table '+@name)

      fetch   next   from   deletecursor   into   @name  

  end  
  close   deletecursor  
  deallocate   deletecursor    

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章