清空数据库所有表数据,表和表结构约束都不变
有两个地方需要改,
第一行和最后一行的testdb改成你的数据库名
- use testdb
- declare @tablename varchar(max)
- declare havetable cursor for select [name] from sysobjects where xtype='U'
- open havetable
- fetch next from havetable into @tablename
- WHILE @@FETCH_STATUS = 0
- begin
- exec('delete from '+ @tablename)
- fetch next from havetable into @tablename
- end
- close havetable
- deallocate havetable
- DUMP TRANSACTION testdb WITH NO_LOG
use testdb declare @tablename varchar(max) declare havetable cursor for select [name] from sysobjects where xtype='U' open havetable fetch next from havetable into @tablename WHILE @@FETCH_STATUS = 0 begin exec('delete from '+ @tablename) fetch next from havetable into @tablename end close havetable deallocate havetable DUMP TRANSACTION testdb WITH NO_LOG