Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Does SQL server take defaut database as "master"?

Author  Topic 

ketu0001
Starting Member

11 Posts

Posted - 2007-06-07 : 09:34:15
Hi
When I execute a query for selecting roles of particular login user from MSSQL server using C++ code, MSSQL server returns roles in master database only. Is this the case that MSSQL database takes master databse as default?
For any other database I mentioned it as " use <database name>" then it returned roles for mentioned login user from mentioned database.

My question is when we do not specify any database , then does MSSQL takes "MAsTER" as default database?

nr
SQLTeam MVY

12543 Posts

Posted - 2007-06-07 : 10:35:08
You can set the default database for a login - it may be overridden by your connection method though.

Which database it returns roles for will depend on the query you have written. If you don't qualify a table with the database name then it will use the current database, if you are using a system sp or function then it will usually get info for the current database but it depends on what you are doing.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

ketu0001
Starting Member

11 Posts

Posted - 2007-06-08 : 00:36:50
My query is :
'select DbRole = g.name, LoginName = l.loginname,DbUser = u.name
from sysusers u, sysusers g, sysmembers m, master.dbo.syslogins l
where g.uid = m.groupuid and g.issqlrole = 1 and
u.sid = l.sid and
u.uid = m.memberuid and g.name like '%' and l.loginname like 'ooousr2'
order by 1, 2'
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-06-08 : 01:00:52
It depends on sql login's default db, by default is master db.
Go to Top of Page

ketu0001
Starting Member

11 Posts

Posted - 2007-06-08 : 02:54:01
Thanks rmiao.
In my query there are three tables as "sysusers u, sysusers g, sysmembers m, master.dbo.syslogins l ".
From which of these is indicator to master db?
or master db is not only mention in the query and is this the case
that since it's not mentioned it's taken by default?
Can you please explaint the concept in details?

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-06-08 : 10:46:14
It will use the database of the connections current context.
When you connect there will be a default database set for the login and you can change that by a use command.
master.dbo.syslogins will refer to master (that's where logins are held) - the other tables will be those in the connections current database.
If you don't want to change database you can qualify the table names (as with sysogins) or use sp_executesql to execute the command in another database.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

ketu0001
Starting Member

11 Posts

Posted - 2007-06-11 : 06:57:37
Thank You. :-)
Go to Top of Page
   

- Advertisement -