How to check if the User exists and Drop User from SQL Server Database

To check if the user exists and drop the user from SQL Server Database if it exists, you can use this code:

USE [Database_Name]
GO
IF EXISTS (SELECT * FROM sys.database_principals WHERE name = N'User_Name')
DROP USER [User_Name]
GO

It will drop the user from the database, without dropping the login from the SQL Server instance.

If the post helped you, please share it:
Pin It

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">