所以我知道基本的SQL,但我不是專家。我維護的系統似乎每隔幾天就會放慢一點,並且我認爲它是來自某個地方的錯誤查詢。SQL查詢優化 - 降低服務器效率
從我所知道的情況來看,我已經將問題縮小到了一兩頁。以下是我認爲導致問題的頁面上的查詢。
select a.s_purchase_order as order_id, a.order_type, a.nobackorder, a.order_note, a.note, a.rqst_dlvry_date, b.customer_name ,c.store_name,(c.store_name + ',' + isnull(c.address1 + ',', ' ') + isnull(c.city + ',', ' ') + isnull(c.state_cd+ ',', ' ') + isnull(c.zipcode, ' ')) as store_info, d.supplier_account
from VW_CustomerOrder a, Customer b, Store c, eligible_supplier d
where a.customer = c.customer
and a.store = c.store
and a.customer = b.customer
and c.customer *= d.customer
and c.store *= d.store
and a.supplier *= d.supplier
and a.purchase_order = @order_id
and a.customer = @customer_id
and [email protected]_id
and a.supplier = @supplier_id
是否有明顯的東西會很慢或導致系統隨着時間變慢?
如果沒有關於表格的更多信息,您甚至可能無法回答。如果是的話,讓我知道,我可以張貼更多的細節。
謝謝!
做你的加入在FROM子句(如下面的答案)不在where子句中,它提高了可讀性。另外,你使用的是什麼DBMS? MySQL的? SQL Server?其他? – Ghost 2012-08-02 17:23:12
@Yaroslav不要將自己的語法偏好強加於他人。您的大寫SQL關鍵字不比小寫關鍵字更正確,並且它們看起來(在我看來)是可怕的。 – meagar 2012-08-02 18:53:44
謝謝你們,這是一個好主意,但我現在得到一個錯誤。感謝您的幫助 – fullOfQuestions 2012-08-02 19:40:50