本文重点介绍如何使用 T-SQL 用户定义的架构在专用 SQL 池中开发解决方案。
传统数据仓库通常使用单独的数据库基于工作负荷、域或安全性创建应用程序边界。
例如,传统的 SQL Server 数据仓库可能包括过渡数据库、数据仓库数据库和一些数据市场数据库。 在此拓扑中,每个数据库作为体系结构中的工作负荷和安全边界运行。
相比之下,专用 SQL 池在一个数据库中运行整个数据仓库工作负荷。 不允许跨数据库联接。 专用 SQL 池要求将仓库使用的所有表存储在一个数据库中。
备注
SQL 池不支持任何类型的跨数据库查询。 因此,需要修改利用此模式的数据仓库实现。
下面是使用用户定义的架构合并工作负载、安全性、域和功能边界的建议:
- 使用专用 SQL 池中的一个数据库运行整个数据仓库工作负荷。
- 合并现有数据仓库环境以使用一个专用 SQL 池数据库。
- 利用 用户定义的架构 提供以前使用数据库实现的边界。
如果以前未使用用户自定义架构,则你有一个全新的开始。 使用旧数据库名称作为专用 SQL 池数据库中用户定义的架构的基础。
如果架构已使用,则有几个选项:
- 删除旧架构名称并重新开始。
- 在表名称前面附加旧架构名称,以保留旧架构名称。
- 在额外架构中的表上实现视图来重建旧架构结构,以保留旧架构名称。
备注
乍一看,选项3可能看起来最具吸引力。 但是,细节决定成败。 视图在专用 SQL 池中是只读的。 任何数据或表的修改都需要在基表上执行。 选项 3 还会在系统中引入一层视图。 如果已在体系结构中使用视图,你可能想要对此进行一些额外的思考。
基于数据库名称实现用户定义的架构:
CREATE SCHEMA [stg]; -- stg previously database name for staging database
GO
CREATE SCHEMA [edw]; -- edw previously database name for the data warehouse
GO
CREATE TABLE [stg].[customer] -- create staging tables in the stg schema
( CustKey BIGINT NOT NULL
, ...
);
GO
CREATE TABLE [edw].[customer] -- create data warehouse tables in the edw schema
( CustKey BIGINT NOT NULL
, ...
);
在表名称前面附加旧架构名称,以保留旧架构名称。 使用模式来界定工作负荷的边界:
CREATE SCHEMA [stg]; -- stg defines the staging boundary
GO
CREATE SCHEMA [edw]; -- edw defines the data warehouse boundary
GO
CREATE TABLE [stg].[dim_customer] --pre-pend the old schema name to the table and create in the staging boundary
( CustKey BIGINT NOT NULL
, ...
);
GO
CREATE TABLE [edw].[dim_customer] --pre-pend the old schema name to the table and create in the data warehouse boundary
( CustKey BIGINT NOT NULL
, ...
);
使用视图保留旧架构名称:
CREATE SCHEMA [stg]; -- stg defines the staging boundary
GO
CREATE SCHEMA [edw]; -- stg defines the data warehouse boundary
GO
CREATE SCHEMA [dim]; -- edw defines the legacy schema name boundary
GO
CREATE TABLE [stg].[customer] -- create the base staging tables in the staging boundary
( CustKey BIGINT NOT NULL
, ...
)
GO
CREATE TABLE [edw].[customer] -- create the base data warehouse tables in the data warehouse boundary
( CustKey BIGINT NOT NULL
, ...
)
GO
CREATE VIEW [dim].[customer] -- create a view in the legacy schema name boundary for presentation consistency purposes only
AS
SELECT CustKey
, ...
FROM [edw].customer
;
备注
架构策略中的任何更改都需要查看数据库的安全模型。 在许多情况下,可以通过在架构级别分配权限来简化安全模型。 如果需要更精细的权限,则可以使用数据库角色。
有关更多开发技巧,请参阅 开发概述。