查询时的 SQL Server 默认数据库 - master [英] SQL Server Default Database when Query - master

查看:53
本文介绍了查询时的 SQL Server 默认数据库 - master的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的 8 年里,我一直在使用 SQL Server Management Studio (SSMS),但我不断遇到问题.当我右键单击一个表并选择 SELECT TOP 2000 ROWS 时,查询编辑器会打开一个包含查询的新文件.这很好,所有这些都是为了快速查看表格.

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.

由 SSMS 生成的查询,然后在括号中包含数据库、架构和表,即 [DB].[dbo].[TableName]

The query that gets generated by SSMS, then has the databse, schema, and table in brackets, i.e. [DB].[dbo].[TableName]

有没有办法在 SELECT TOP 2000 ROWS 命令​​上设置默认数据库,而不是将默认数据库设置为master"?

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' ?

另一种解决方法是单击表,然后执行新查询",这将保留当前数据库,然后我必须输入SELECT * FROM TableName"

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'

推荐答案

在 SSMS 中,转到安全 > 登录 - 选择您的登录名,然后右键单击并选择属性 - 在选项卡底部是一个名为默认数据库"的选项" - 这就是你想要改变的.

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.

这篇关于查询时的 SQL Server 默认数据库 - master的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆