SQL 清除数据库中所有表的数据(保留结构)
使用游标和truncate语句:
declare c cursor for
select NAME from sysobjects where xtype='U'
declare @t varchar(200)
open c
fetch next from c into @t
while @@FETCH_STATUS=0
begin
exec('truncate table '+@t)
fetch next from c into @t
end
close c
注:exec执行语句可根据自己的需求更改,但是一定要慎用drop,因为drop是将所有的表结构都清除了