I've been using SQL Server Management Studio (SSMS) for the last 8 years, and I keep on stumbling upon a problem. When I right click on a Table, and select SELECT TOP 2000 ROWS, the query editor opens up a new file with the query inside. This is nice and all for a quick review of the table.
The problem I have is the default database is changed from the actual database to the master database. I have sysadmin rights.
The query that gets generated by SSMS, then has the databse, schema, and table in brackets, i.e. [DB].[dbo].[TableName]
Is there a way to set the default database on the SELECT TOP 2000 ROWS command, to NOT go and set the default database to 'master' ?
The other workaround is to click on the table, and then do a 'New Query', which will keep the current database, and then I have to type in 'SELECT * FROM TableName'
Open the database server in the Object Explorer (left panel). In Object Explorer, open Security > Logins. Right-click the user you created and choose Properties. On the General page, select a Default database.
SQL Server comes installed with four system databases by default. They are master, model, msdb, and TempDB.
Whenever you connect to any database server in SSMS, by default Master database is selected as current database. But you work on different database and every time you have to change database either by using USE statement or changing selected db by mouse. It is very irritating task.
In SSMS go to Security > Logins - choose your login, then right-click and choose Properties - at the bottom of the tab is an option called "Default Database" - this is what you want to change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With