這應該做的伎倆......
Declare @ApplicationName nvarchar(256),
@UserName nvarchar(256),
@TablesToDeleteFrom int = 15,
@NumTablesDeletedFrom int
Declare cur
Cursor For
Select aa.LoweredApplicationName,
au.LoweredUserName
From [dbo].[aspnet_Users] au
Join [dbo].[aspnet_Applications] aa
On au.ApplicationId = aa.ApplicationId
Where LastActivityDate < '1/1/2015'
Open cur
Fetch Next
From cur
Into @ApplicationName,
@UserName
While @@FETCH_STATUS = 0
Begin
Exec [dbo].[aspnet_Users_DeleteUser]
@ApplicationName,
@UserName,
@TablesToDeleteFrom,
@NumTablesDeletedFrom Out
Fetch Next
From cur
Into @ApplicationName,
@UserName
End
Close cur
Deallocate cur
你能提供一個例子PROC電話? @TablesToDeleteFrom是我想知道的。你用什麼價值呢? –
'EXEC \t @return_value = [DBO]。[aspnet_Users_DeleteUser] \t \t @ApplicationName = N '/', \t \t @UserName = N'usernameToDelete」, \t \t @TablesToDeleteFrom = 15, \t \t @NumTablesDeletedFrom = @NumTablesDeletedFrom OUTPUT '@TablesToDeleteFrom參數爲15意味着從所有的aspnet表中刪除。 – HackWeight