SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


What is your default database set to?


What is your default database set to?

Author
Message
bkubicek
bkubicek
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3347 Visits: 824
Comments posted to this topic are about the item What is your default database set to?
EdVassie
EdVassie
SSCertifiable
SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)

Group: General Forum Members
Points: 7473 Visits: 3875
It is definitely good to know the implications of choosing a default database.

A few years back I worked with the Remedy help desk system. I do not know if it has been changed for this issue, but back then the default database for the Remedy login had to be the Remedy database. The account also needed to be the db owner account as shown in database properties, or be set to use a default schema of dbo. This is because Remedy would create tables as required, and often used the syntax "CREATE TABLE xxx". The read statements typically took the form "SELECT FROM dbo.xxx" or "SELECT FROM remedydb.dbo.xxx", so you needed to make sure the defaults that applied to the table creates would work with the explicit names used for the select statements.

You are unlikely to have a one-size-fits-all solution to allocating the default database for a user, but you definitely need to know any special needs the user account has, and the implications around the database you choose.

Original author: SQL Server FineBuild 1-click install and best practice configuration of SQL Server 2017 2016, 2014, 2012, 2008 R2, 2008 and 2005. 14 Mar 2017: now over 40,000 downloads.Disclaimer: All information provided is a personal opinion that may not match reality.Quote: When I give food to the poor they call me a saint. When I ask why they are poor they call me a communist. - Archbishop Hélder Câmara
atoth
atoth
Valued Member
Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)Valued Member (50 reputation)

Group: General Forum Members
Points: 50 Visits: 106
Happened to me just the other day! Took me a while to figure it out :-)
AppSup_dba
AppSup_dba
Old Hand
Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)

Group: General Forum Members
Points: 382 Visits: 716
I learnt it the hard way... while i cleaned up few databases (after migration), users complaint of not being able to connect... though error message was quite obvious and hence i changed the default db of logins to fix the issue

Cheers
olivier.kovacs
olivier.kovacs
SSC Veteran
SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)SSC Veteran (243 reputation)

Group: General Forum Members
Points: 243 Visits: 39
We use a lot of applications with dedicated user and roles.
In that particular case, since the account should only have access to that specific DB, we do default to the specific DB as default.
For other "management" accounts, we default to master. We identified this issue a long time ago - the hard way like many - and without really thinking about it, we adopted this method. If your DB is down, the application that requires it will be down, which is really easy to spot Smile

Thanks for the good explanation.
Olivier
Mauve
Mauve
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2010 Visits: 2059
I assign all of my SQL Server logins to the tempdb as the default database. NEVER master. This way no harm can be done by an application that just connects to the server without specifying a database name as part of the connection string. Ideally, I'd like to see an option of "none".


(PHB) I think we should build an SQL database. (Dilbert) What color do you want that database? (PHB) I think mauve has the most RAM.
Nadrek
Nadrek
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2473 Visits: 2733
Mauve (11/14/2013)
I assign all of my SQL Server logins to the tempdb as the default database. NEVER master. This way no harm can be done by an application that just connects to the server without specifying a database name as part of the connection string. Ideally, I'd like to see an option of "none".


All users except sysadmins get tempdb as a default - anything they add there gets cleaned up next patch/reboot cycle, regardless.

Sysadmins get master, in case tempdb isn't available for some reason (tempdb volume failure, and so on).
Adam Seniuk
Adam Seniuk
Say Hey Kid
Say Hey Kid (680 reputation)Say Hey Kid (680 reputation)Say Hey Kid (680 reputation)Say Hey Kid (680 reputation)Say Hey Kid (680 reputation)Say Hey Kid (680 reputation)Say Hey Kid (680 reputation)Say Hey Kid (680 reputation)

Group: General Forum Members
Points: 680 Visits: 1040
Mauve (11/14/2013)
I assign all of my SQL Server logins to the tempdb as the default database. NEVER master. This way no harm can be done by an application that just connects to the server without specifying a database name as part of the connection string. Ideally, I'd like to see an option of "none".


I second this, I really wish that we could set this as a default so when someone creates a new user it would be already entered.


Over 12yrs in IT and 10yrs happily stuck with SQL.

http://aseniuk.wordpress.com
- SQL 2008/R2/2012/2014
- Oracle 8/9/10/11
- MySQL 4/5
Andy Warren
Andy Warren
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: Moderators
Points: 15095 Visits: 2730
I like the idea of defaulting to tempdb. I've always used master, agree with not using any real db as a default.

Andy
SQLAndy - My Blog!
Connect with me on LinkedIn
Follow me on Twitter
james.of.rivendell
james.of.rivendell
SSC-Enthusiastic
SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)

Group: General Forum Members
Points: 120 Visits: 126
Did you try with sqlcmd?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search