tsql - How to check if the USER is already created in the database or not in SQL? -



tsql - How to check if the USER is already created in the database or not in SQL? -

is there way can know if user(not login) created in database? mean user not login, since, know how check login. need check user created within specific db & role assigned it.

this code checking login:

select name sys.server_principals name = 'test_user'

but how user? since need create user , assign role if not created. otherwise, go on without creating.

thanks

how about:

use (your database want check user's existence in) select * sys.database_principals name = '(your user name check here)'

sys.server_principals shows logins defined on server level - sys.database_principals shows principals (e.g. user accounts) on database level.

sql tsql

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -