清空SQL Server数据库中所有的用户表
清空数据库中所有的用户表
declare crsr cursor
for SELECT [name] FROM DBO.SYSOBJECTS
WHERE OBJECTPROPERTY(ID,N'IsTable')=1 and type = 'U' and [name] <> 'dtproperties' --and crdate...--可以为crdate字段指定表的创建日期
open crsr
declare @tblName sysname
fetch crsr into @tblName
EXEC('truncate table '+@tblName)
while @@fetch_status=0
fetch next from crsr into @tblName
EXEC('truncate table '+@tblName)
close crsr
deallocate crsr --删除以释放游标
declare crsr cursor
for SELECT [name] FROM DBO.SYSOBJECTS
WHERE OBJECTPROPERTY(ID,N'IsTable')=1 and type = 'U' and [name] <> 'dtproperties' --and crdate...--可以为crdate字段指定表的创建日期
open crsr
declare @tblName sysname
fetch crsr into @tblName
EXEC('truncate table '+@tblName
while @@fetch_status=0
fetch next from crsr into @tblName
EXEC('truncate table '+@tblName
close crsr
deallocate crsr --删除以释放游标