exec sp_MSforeachtable 'truncate table [?]'

解决方案 »

  1.   

    自动生成数据库的清空脚本
    http://blog.csdn.net/roy_88/archive/2008/05/21/2467748.aspx
      

  2.   

    truncate
      

  3.   

    --使用游标删除所有表内容
    set nocount on
    declare Trun_Cur cursor
    for select name from sys.tabless 
    declare @PName varchar(100),@SQL varchar(255)
    open Trun_cur
    fetch next from Trun_cur into @Pname
    while @@fetch_status=0
    begin
    set @SQL='truncate table '+@pname
    exec (@SQL)
    fetch next from Trun_cur into @Pname
    end
    close Trun_cur
    deallocate Trun_cur
    set nocount off
      

  4.   

    刚才的 sys.tables 多写了一个S。
      

  5.   

    谢谢了!不过还是不能应用到我的数据库上!因为该表正由 FOREIGN KEY 约束引用。
    小梁,你给我的哪个连接,能不能修改下!