为什么我必须查询SSM中的完整路径?

发布于 2025-02-13 07:25:59 字数 198 浏览 0 评论 0原文

我想在SSM中查询,但我总是必须添加特定的模式作为前缀,尽管我已经运行了查询:

USE (the specific db I wanna use);   
GO 

在查询时,我应该为SSMS做些什么才能从特定的DB和Schemas中带回桌子?

I want to query in ssms but I always have to add the specific schema as a prefix, although I have ran the query:

USE (the specific db I wanna use);   
GO 

What should I do for ssms to bring back only tables from the specific db and schemas while querying?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沧笙踏歌 2025-02-20 07:25:59

在SQL Server中,您可以使用完全合格的名称。该部分由三个部分组成(尽管从技术上讲,当使用链接服务器时,您也可以添加一个Servername零件):

  • 数据库
  • 架构

,并且可以以以下方式使用:

SELECT * FROM <database>.<schema>.<table>

使用关键字简单地更改您执行SQL命令的上下文。这与使用SSMS中的下拉框更改为其他数据库是相同的。

通过切换数据库上下文,您通常可以跳过上面的查询部分。通过切换上下文,假定所有命令将在您更改为的数据库中执行。

它仍然存在的原因是否要访问同一SQL Server实例上不同数据库中物理位置的对象。

模式只是将桌子分组的一种方式。默认模式是数据库所有者(DBO)。如果省略模式名称,则假定该对象在DBO架构中。因此,假定以下2个命令是相同的:

SELECT * FROM dbo.MyTable
SELECT * FROM MyTable

但是,使用架构是构造数据库的一种好方法,因为您可以在同一模式中逻辑上将相关的对象分组,并相应地分配权限。

从OLTP的角度来看,您可以使用订单的架构,而销售。这样一来,人们就更容易过滤他们感兴趣的对象,而DBA可以将访问模式访问到特定部门。

如果您使用数据仓库,则可以看到提取架构,stage架构以及fact> fact and code> dimension dimension dimension < /代码>模式。

Within SQL Server, you use the Fully Qualified Name. That consists of three parts (though technically, when using a linked server, you could add a servername part as well):

  • Database
  • Schema
  • Table

And can be used in the following manner:

SELECT * FROM <database>.<schema>.<table>

The USE keyword simply changes the context in which you are executing a SQL command. It's identical to using the drop-down box in SSMS to change to a different database.

By switching the database context, you can typically skip the part of the query above. By switching context, it is assumed all commands will be executed within the database you changed to.

The reason it's still there is if you want to access objects that physically reside within a different database on the same SQL Server instance.

The schema is just a way to group your tables. The default schema is database owner (dbo). If you omit the schema name, it's assumed the object is in the dbo schema. So the following 2 commands are assumed to be identical:

SELECT * FROM dbo.MyTable
SELECT * FROM MyTable

However, using schemas is a great way to structure your database, as you can logically group related objects within the same schema, and assign permissions accordingly.

From an OLTP perspective, you could have a schema dealing with orders, and one with sales. That way it is easier for people to filter only the objects they are interested in, and for the dba to limit access to schemas to specific departments.

If you work with data warehousing, it's not unusual to see an Extract schema, a Stage schema, and a Fact and Dimension schema.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文