I connected to SQL Server with Windows Authentication (Admin).
Then, I created a login for my SQL Server 2005 Express as:
CREATE LOGIN bob WITH PASSWORD = 'bobpass'.
Now, I closed SQL Server & then again opened it & this time I connected it with the login 'bob'.
Now, I executed this : SELECT CURRENT_USER.
It gave the output : guest
Why so?
Is this because I didn't create any user inside the bob
login?
CURRENT_USER will return a database principal (an user).
bob
is a server principal (a login). If you didn't grant access to any database and you didn't add bob to any builtin server security groups, then he will not have access to any database except master and tempdb. In those two databases, he will be recognized asguest
. This is the default, you may notice differences from this description if you have something changed in your deployment from a fresh installation (eg. you may discover thatbob
has access to more databases because those databases have enabledguest
).So basically you guessed right:
bob
isguest
because he does not have an explicit database principal (an user) nor is he member ofsysadmin
(in which case he would bedbo
in every database).