Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Monday 22 April 2024

Remove User from Sql server

To remove a user called John from SQL Server, you can follow these steps:


Here's an example of the T-SQL command to remove a user named 'username':


DROP USER username;


1. Connect to SQL Server Management Studio (SSMS): Log in to SSMS using an account with administrative privileges.


2. Identify the User: Before removing the user, make sure to identify the correct username. You can use the following query to check if the user exists:


   SELECT name FROM sys.database_principals WHERE type_desc = 'SQL_USER' AND name = 'John';


3. Revoke Permissions (Optional): If the user has been granted any permissions, you may want to revoke them before removing the user. Use the REVOKE statement to revoke permissions as needed.


4. Remove the User: Once you've confirmed the user's existence and revoked any permissions, you can proceed to remove the user using the DROP USER statement:


   DROP USER John;


   Replace John with the actual username you want to remove.


5. Confirm Removal: To verify that the user has been successfully removed, you can re-run the query from step 2. If the user no longer exists in the results, it means the removal was successful.


6. Disconnect Any Active Sessions (Optional): If there are any active sessions for the user, you may want to disconnect them before removing the user. This step is optional and depends on your specific requirements.


7. Exit SSMS: Once you've confirmed the removal of the user, you can exit SSMS.

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.