删除库中所有表中的数据
declare @TableName nvarchar(250) --声明读取数据库所有数据表名称游标mycursor1 declare mycursor1 cursor for select name from dbo.SysObjects WHERE OBJECTPROPERTY(ID, 'IsUserTable') = 1 open mycursor1 --从游标里取出数据赋值到我们刚才声明的数据表名变量中 fetch next from mycursor1 into @TableName --如果游标执行成功 while (@@fetch_status=0) begin --执行删除 --exec('truncate table ['+@TableName+']') exec('delete from ['+@TableName+']') --用游标去取下一条记录 fetch next from mycursor1 into @TableName end --关闭游标 close mycursor1 print '游标1关闭' --撤销游标 deallocate mycursor1 print '撤销游1'