Is there is a way that from it I can know if the user(not the login) is already created in the database? I mean the user not the login, since, I know how to check for the login. I need to check for the user that is created inside a specific DB & a role assigned to it.
This is the code for checking for the login:
SELECT name FROM sys.server_principals WHERE name = 'test_user'
USE (your database you want to check the user's existence in) SELECT * FROM sys.database_principals WHERE name = '(your user name to check here)'
sys.server_principals shows you the logins defined on the server level -
sys.database_principals shows you the principals (e.g. user accounts) on a database level.