How to Remove a User in PostgreSQL?
Remove a User
Write a PostgreSQL query to delete the user temp_user.
Solution:
-- Drop a user
DROP USER temp_user;
Explanation:
- Purpose of the Query:
- Permanently removes the user from the database.
- Key Components:
- DROP USER temp_user: Deletes the user.
- Real-World Application:
- Useful when cleaning up unused accounts.
Notes:
- The user must not own any objects before deletion.
For more Practice: Solve these Related Problems:
- Write a PostgreSQL query to safely remove a user by first transferring their owned objects to another user.
- Write a PostgreSQL query to delete a user and archive their account details in a backup table before removal.
- Write a PostgreSQL query to remove a user only if they have not executed any transactions in the past 30 days.
- Write a PostgreSQL query to drop a user while automatically revoking all permissions granted on all schemas.
Go to:
PREV : List All Users and Roles.
NEXT : Lock a User Account.
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
