久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在不損失性能的情況下保持發(fā)票金額正確?

Keep invoice sum right without losing performance?(在不損失性能的情況下保持發(fā)票金額正確?)
本文介紹了在不損失性能的情況下保持發(fā)票金額正確?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有兩張桌子...

CREATE TABLE [dbo].[Invoice](
    [InvoiceID] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
    [TotalSumBeforeTax] [decimal](12, 2) NOT NULL,
    [TotalSumAfterTax] [decimal](12, 2) NOT NULL
)

CREATE TABLE [dbo].[InvoiceItem](
    [InvoiceItemID] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
    [InvoiceID] [uniqueidentifier] NOT NULL,
    [AmountBeforeTax] [decimal](12, 2) NOT NULL,
    [AmountAfterTax] [decimal](12, 2) NOT NULL
) 

發(fā)票表保存了所有引用該發(fā)票的 InvoiceItems 的計算總和.

The Invoice table holds a calculated sum of all the InvoiceItems that refer to that Invoice.

我需要幫助找出最佳做法,以在不損失性能的情況下保持發(fā)票金額正確.

I need help figuring out the best practice to keep the Invoice sum correct without losing performance.

計算列?

如果我對 Invoice 表中的 TotalSumBeforeTaxTotalSumAfterTax 使用計算列,則通過 InvoiceItem 表中的函數(shù)獲取值,它不會持久化并且會很慢,因為我在 InvoiceItem 表中有數(shù)十萬行.

If I use a calculated column for TotalSumBeforeTax and TotalSumAfterTax in the Invoice table, that fetches values via a function from the InvoiceItem table, it's not persisted and will be very slow, since I have hundreds of thousands of rows in the InvoiceItem table.

觸發(fā)?

我還考慮在 InvoiceItem 表上使用觸發(fā)器,然后更新 Invioce TotalSumBeforeTax TotalAfterBeforeTax 列.

I also thought about using a trigger on the InvoiceItem table and then updating the Invioce TotalSumBeforeTax TotalAfterBeforeTax columns.

怎么辦?

在列出 Invoice 表的多行時,有沒有辦法始終保持 TotalSumBeforeTaxTotalSumAfterTax 列最新,同時對性能的影響最小?

Is there a way to always keeping the TotalSumBeforeTax and TotalSumAfterTax columns up-to-date with minimal impact on performance when listing many rows of the Invoice table?

推薦答案

我認(rèn)為您根本不應(yīng)該保留這些列.只需在 InvoiceItem 表上創(chuàng)建一個索引,該索引將具有 InvoiceID 并包含 AmountBeforeTaxAmountAfterTax 列,并且需要時使用簡單的 sumgroup by 查詢進(jìn)行計算:

I would argue that you shouldn't keep these columns at all. Just create an index on the InvoiceItem table that will have the InvoiceID and include the AmountBeforeTax and AmountAfterTax columns, and calculate when needed using a simple sum and group by query:

SELECT InvoiceID
    , SUM(AmountBeforeTax) AS TotalSumBeforeTax
    , SUM(AmountAfterTax) AS TotalSumAfterTax
FROM dbo.InvoiceItem
GROUP BY InvoiceID

根據(jù)經(jīng)驗,不應(yīng)該存儲容易計算的東西 - 因為計算比同步存儲的值更容易.

As a rule of thumb, things that can easily be computed shouldn't be stored - because it's easier to compute than to synchronize the stored values.

順便說一句,如果涉及稅收,不應(yīng)該是price而不是amount嗎?

BTW, if there's a tax involved shouldn't it be price and not amount?

這篇關(guān)于在不損失性能的情況下保持發(fā)票金額正確?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Modify Existing decimal places info(修改現(xiàn)有小數(shù)位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關(guān)名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運(yùn)算符字符串中刪除重復(fù)項)
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關(guān)系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 99精品国产一区二区青青牛奶 | 亚洲精品国产a久久久久久 午夜影院网站 | 日韩在线观看视频一区 | 欧美全黄 | 91影院在线观看 | 久久国产一区二区 | 精品久久精品 | 操操日| 一区二区三区免费 | 极品久久 | 国产综合视频 | 国产精品精品3d动漫 | 国产高清精品一区二区三区 | 国产福利小视频 | 天堂在线www | 久久久久久久久久一区二区 | 成人欧美一区二区三区白人 | 成人在线视频免费观看 | 免费av一区二区三区 | 久久狼人天堂 | 国产在线视频一区二区 | 特一级毛片 | 激情在线视频网站 | 午夜免费看 | 久久精品亚洲精品国产欧美 | 一级片片 | 一区二区三区免费 | 亚洲一区网站 | 97国产超碰| 欧美精品1区2区3区 免费黄篇 | 国产精品日韩一区二区 | 97精品国产97久久久久久免费 | 人妖av| 日韩欧美精品在线播放 | 国产一区二区三区日韩 | 欧美日韩视频在线第一区 | 一区二区三区四区在线视频 | 少妇黄色 | 日本a v在线播放 | 亚洲精品一二三区 | 日本一区二区三区在线观看 |