信息发布→ 登录 注册 退出

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

发布时间:2026-01-11

点击量:
-->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'')'
标签:# Author  # schemas  # sys  # table  # truncate  # close  # sp_msforeachtable  # deallocate  # select  # Date  # Title  # gt  # MSSQL  # BR  # varchar  # cursor  # cuser  # uname  # declare  # span  # 库里  # 数据  # 用户  
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!