MSSQL 中怎么删除数据库里某个用户所有表里的数据

MSSQL 中怎么删除数据库里某个用户所有表里的数据,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

-->Title:删除数据库里某个用户所有表里的数据 -->Author:wufeng4552 -->Date :2009-09-21 15:08:41 --

方法1

代码如下: 

 declare @uname varchar(20) declare cuser cursor for select so.name from sysobjects so,sysusers su where so.uid=su.uid and su.name='Stone' and so.xtype='U' open cuser fetch next from cuser into @uname while(@@fetch_status=0) begin exec('truncate table [Stone].['+@uname+']') fetch next from cuser end close cuser deallocate cuser

--方法2

代码如下:

 exec sp_msforeachtable @command1="truncate table ? ;",@whereand='and schema_id = (select schema_id from sys.schemas where [name] =''Stone'')'

看完上述内容,你们掌握MSSQL 中怎么删除数据库里某个用户所有表里的数据的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!