物化视图还是CDC?

发布于 2024-08-21 08:55:04 字数 654 浏览 4 评论 0原文

我有两个包含数百万条记录的表(使用 SQL 2008 存储)的视图。

CREATE VIEW VwSalesAge
AS
    SELECT
        Transactions.ID
        ,Transactions.Amount
        ,Customer.ID
                ,Customer.Name
        ,Customer.Age
    FROM Transactions 
        INNER JOIN Customer 
            ON Transactions.CustomerID=Customer.ID

现在我想使用物理表来存储这些信息,以避免扫描大型表以进行更小的查询,例如“

SELECT * 
FROM VsSalesAge 
WHERE Customer.ID = 123

那么就性能而言,哪种方法是最好的方法”。

  1. 在两个表上使用更改数据捕获并识别更改和 将它们应用到新表“TbSalesAge”
  2. 使用物化视图而不是物理表
  3. 其他一些方法(请解释...)

PS:我不需要实时副本

I have a view on two tables (stored using SQL 2008) with millions of records.

CREATE VIEW VwSalesAge
AS
    SELECT
        Transactions.ID
        ,Transactions.Amount
        ,Customer.ID
                ,Customer.Name
        ,Customer.Age
    FROM Transactions 
        INNER JOIN Customer 
            ON Transactions.CustomerID=Customer.ID

Now I want to use a physical table to store this information to avoid scannig of large tables for even smaller queries like

SELECT * 
FROM VsSalesAge 
WHERE Customer.ID = 123

So which one is the best approach in terms of performance.

  1. USE Change Data Capture on both tables and identify changes and
    apply them on the new table 'TbSalesAge'
  2. Use a materialized view instead of a physical table
  3. Some other method (explain please...)

PS: I don't need real-time replica

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

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

发布评论

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

评论(1

红焚 2024-08-28 08:55:04

恕我直言,我认为最好的方法是使用索引视图。您将需要使用 SCHEMABINDING 选项创建视图,并且对计算列、分组函数等有一些限制,但我认为这将为您提供单个合并对象,并通过您正在寻找的索引来提高性能。

IMHO, I think the best approach would be to use an Indexed View. You will need to create the view with the SCHEMABINDING option and there are some restrictions on computed columns, grouping functions, etc., but I think this gets you the single consolidated object with the performance improvements with indexing you're looking for.

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