> ## Content Index
> Fetch the complete content index at: https://blog.tsd.digital/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to: Remove all users from the ASP.Net Membership database by application name
- URL: https://blog.tsd.digital/how-to-remove-all-users-from-the-aspnet-membership-database-by-application-name/
- Published: 2010-12-22T19:08:47.000Z
- Updated: 2010-12-22T19:08:47.000Z
- Author: Tim Gaunt
- Tags: Development, SQL Server, Testing, #Import 2025-04-01 05:37

![delete_key[1]](https://storage.ghost.io/c/64/5b/645b11c2-b436-444c-a523-58dca4ca7bd8/content/images/tim/images/53bad6f4d949_DE2B/delete_key1.jpg)

A while ago I wrote about [How to: Remove users from the ASP.Net membership database](http://blogs.thesitedoctor.co.uk/tim/2008/01/13/How+To+Remove+Users+From+The+ASPNet+Membership+Database.aspx?ref=blog.tsd.digital) which showed you how to remove a single user from the ASP.Net membership database from SQL Management Studio. That's great when you're deleting one or two users but what if you're testing and need to delete all users associated with an application? 

There's a little more work involved with that one but it's not too difficult, rather than passing in the member's id, you pass in the ApplicationName (same as you set in your web.config) and it will find the various users that match and remove them for you.

USE DatabaseName --This should be your database name GO BEGIN TRANSACTION DECLARE @ApplicationName nvarchar(256) SET @ApplicationName = '##YOUR APPLICATION NAME -AS SET IN THE WEB.CONFIG ##' --Lowercase it so it matches LoweredApplicationName exactly SET @ApplicationName = LOWER(@ApplicationName) --Values in the aspnet\_Profile table DELETE p FROM dbo.aspnet\_Applications a INNER JOIN dbo.aspnet\_Users u ON a.ApplicationId = u.ApplicationId INNER JOIN dbo.aspnet\_Profile p ON u.UserId = p.UserId WHERE a.LoweredApplicationName = @ApplicationName --Values in the aspnet\_UsersInRoles table DELETE r FROM dbo.aspnet\_Applications a INNER JOIN dbo.aspnet\_Users u ON a.ApplicationId = u.ApplicationId INNER JOIN dbo.aspnet\_UsersInRoles r ON u.UserId = r.UserId WHERE a.LoweredApplicationName = @ApplicationName --Values in the aspnet\_PersonalizationPerUser table DELETE p FROM dbo.aspnet\_Applications a INNER JOIN dbo.aspnet\_Users u ON a.ApplicationId = u.ApplicationId INNER JOIN dbo.aspnet\_PersonalizationPerUser p ON u.UserId = p.UserId WHERE a.LoweredApplicationName = @ApplicationName --Values in the aspnet\_Membership table DELETE m FROM dbo.aspnet\_Applications a INNER JOIN dbo.aspnet\_Users u ON a.ApplicationId = u.ApplicationId INNER JOIN dbo.aspnet\_Membership m ON u.UserId = m.UserId WHERE a.LoweredApplicationName = @ApplicationName --Values in the aspnet\_users table DELETE u FROM dbo.aspnet\_Applications a INNER JOIN dbo.aspnet\_Users u ON a.ApplicationId = u.ApplicationId WHERE a.LoweredApplicationName = @ApplicationName ROLLBACK TRANSACTION