Delete the implementation statement of data in all tables of a user in the database.
Delete the implementation statement of data in all tables of a user in the database.
--> Title: delete data in all tables of a user in the database.
--> Author: wufeng4552
--> Date: 15:08:41
-- Method 1
The code is as follows:
Declare @ uname varchar (20)
Declare cuser cursor
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 '')'