日期:2014-05-17  浏览次数:20919 次

truncate database
有这样类似的语法或者比较简洁的方法么?

------解决方案--------------------
没有,只能从sys.objects或者sys.tables里面拼接truncate 语句,
------解决方案--------------------
--try
sp_MSforeachtable
------解决方案--------------------

use 数据库名
declare @str varchar(max)
set @str=''
select @str=@str+' truncate table '+quotename(name,'')+';'
from sysobjects where xtype='U' and category=0 
--and name not in('table','user','return','order','客户信息')
--print @str
exec(@str)

------解决方案--------------------
try this,

use [数据库名]
go

exec sp_MSforeachtable "truncate table ?"

------解决方案--------------------
--删除当前数据库所有表中的数据
sp_MSforeachtable @command1='Delete from ?'
sp_MSforeachtable @command1 = "TRUNCATE TABLE ?"

------解决方案--------------------
declare @sql nvarchar(4000);

set @sql  = ''

select @sql = @sql + 'truncate table [' + t.name + '];' 
from sys.tables t

--输出语句
select @sql

exec(@sql)

------解决方案--------------------
你这个是要清库吧
------解决方案--------------------
可以建议微软在后续版本加上这个命令,不过这个truncate database 太危险了
------解决方案--------------------
--删除当前数据库所有表中的数据
sp_MSforeachtable @command1='Delete from ?'
sp_MSforeachtable @command1 = "TRUNCATE TABLE ?"