SQL Server Default Database when Query - master

僤鯓⒐⒋嵵緔 提交于 2020-01-03 06:58:04

问题


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'


回答1:


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.



来源:https://stackoverflow.com/questions/10928161/sql-server-default-database-when-query-master

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!