select @n=1
insert #temp(tablename) SELECT distinct sobjects.name
FROM sysobjects sobjects
WHERE sobjects.xtype = 'U'
select @rows = @@rowcount
while @n <= @rows
begin
declare @tablename nvarchar(50)
select @tablename = (select tablename from #temp where id = @n)
--允许将显式值插入表的标识列中 ON-允许 OFF-不允许
--exec ('set identity_insert '+@tablename+' ON')--打开
exec ('TRUNCATE TABLE '+@tablename)
print(@tablename)
select @n = @n + 1
end
go