How to delete data from all tables of a user in a database in MSSQL
MSSQL how to delete all the table data of a certain user in the database, I believe many inexperienced people are helpless about this, for this reason this article summarizes the causes and solutions of the problem, through this article I hope you can solve this problem.
-->Title: Delete data from all tables of a user in the database-->Author:wufeng4552 -->Date :2009-09-21 15:08:41 --
Method 1
The code is as follows:
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
- Method 2
The code is as follows:
exec sp_msforeachtable @command1="truncate table ? ;",@whereand='and schema_id = (select schema_id from sys.schemas where [name] =''Stone'')'
After reading the above, do you know how to delete all the data in a user's table in MSSQL? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!