gpt4 book ai didi

sql-server - 如何在 SQL Server 中创建架构绑定(bind)的跨数据库 View

转载 作者:搜寻专家 更新时间:2023-10-30 20:17:40 25 4
gpt4 key购买 nike

我正在尝试在 SQL Server 2008 上创建索引 View 。我有一个主数据库,我无法在其中进行任何更改(在添加表、 View 等方面)。但是,出于各种原因,我需要创建一些不同的 View 来处理实时数据。

我已经在我的主数据库旁边创建了一个新数据库,因此我可以在那里创建 View 。我能够很好地创建 View ,但我想索引一些较大的 View 。但是,当我尝试跨数据库创建模式绑定(bind) View 时,我收到以下错误:

Cannot schema bind view 'dbo.Divisions' because name 'master.dbo.hbs_fsdv' is invalid for schema binding. Names must be in two-part format and an object cannot reference itself.

由于我要跨数据库使用 View ,所以我必须以三部分格式引用名称。

我的 View 创建语句:

CREATE VIEW dbo.Divisions WITH SCHEMABINDING AS
SELECT master.dbo.hbs_fsdv.seq_ AS DivisionID,
master.dbo.hbs_fsdv.fs_division_desc_ AS Description
FROM master.dbo.hbs_fsdv

如何在 SQL Server 中创建索引跨数据库 View ?

最佳答案

简单明了。你不能。来自 MSDN 页面:

The view must reference only base tables that are in the same database as the view.

https://msdn.microsoft.com/en-us/library/ms191432.aspx

关于sql-server - 如何在 SQL Server 中创建架构绑定(bind)的跨数据库 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29518044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com