Hac*_*ght 5 sql-server asp.net stored-procedures asp.net-membership
我正在使用标准的aspnet成员资格表,我正在维护我们的数据库.我们希望删除所有未登录一年的用户.
我知道如何调用aspnet_Users_DeleteUser存储过程以删除单个用户,但是如何使用它来删除所有用户aspnet_Users.LastActivityDate < '1/1/2015'呢?
我可以编写一个SELECT语句来输出要删除的用户名,但是如何在每个语句上执行该过程呢?
这应该是诀窍......
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2925 次 |
| 最近记录: |