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

TSQL 常量...使用變量還是文字?

TSQL Constants... Use Variable or Literal?(TSQL 常量...使用變量還是文字?)
本文介紹了TSQL 常量...使用變量還是文字?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我只是在閱讀我公司的代碼指南,它說永遠不要將變量視為 sql server 中的常量,而是使用文字.原因是當你在查詢中使用變量時,sql server 無法建立一個好的執行計劃.

I'm just reading my company's code guidelines and it says to never treat variables as a constant in sql server, use literals instead. The reasoning is that sql server can't build a good execution plan when you're using variables in the query.

有人知道這是否仍然正確嗎?我們使用的是 MSSQL 2005,此文檔可能是為 2000 年編寫的.

Anybody know if this is still true? We're using MSSQL 2005 and this document may have been written for 2000.

推薦答案

這對于 SQL Server 2005 來說通常"是正確的,因為它現在嘗試為盡可能多的查詢預先生成執行計劃.您的里程可能會有所不同,因為它取決于您的數據和您的 SARG(測試您的查詢計劃并查看),但此 tecdoc(他們使用的是 SQL Server 2005 的預發布版本)指出:

This is "generally" true for SQL Server 2005 since it now tries to pre-generate execution plans for as many queries as possible. Your mileage may vary since it depends on your data and your SARG (test your query plans and see) but this tecdoc (they were using a pre-release version of SQL Server 2005) states:

http://www.microsoft.com/technet/prodtechnol/sql/2005/qrystats.mspx

避免使用局部變量查詢

如果在查詢中使用局部變量謂詞而不是參數或字面上,優化器求助于降低質量的估計或猜測謂詞的選擇性.用查詢中的參數或文字而不是局部變量,并且優化器通常能夠選擇一個更好的查詢計劃.例如,考慮這個使用本地的查詢變量:

If you use a local variable in a query predicate instead of a parameter or literal, the optimizer resorts to a reduced-quality estimate, or a guess for selectivity of the predicate. Use parameters or literals in the query instead of local variables, and the optimizer typically will be able to pick a better query plan. For example, consider this query that uses a local variable:

這篇關于TSQL 常量...使用變量還是文字?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 欧美在线不卡 | 在线一区二区观看 | 久综合 | 日韩成人av在线 | 久久成人一区 | 美女天天操 | 成人在线免费电影 | 91青娱乐在线 | 日韩精品视频在线 | 精品欧美乱码久久久久久1区2区 | 99这里只有精品视频 | 91视频中文 | 精品国产乱码久久久久久88av | 国产欧美在线观看 | 国产乡下妇女做爰 | 国产1区2区在线观看 | 天堂一区在线观看 | 国产一级视频在线播放 | 日韩中文字幕 | 久久婷婷色 | 久久精彩视频 | 欧美久久精品一级c片 | 欧美一区二区免费在线 | 999精品网| 最近中文字幕在线视频1 | 九一在线 | 国产精品成人一区二区三区夜夜夜 | 少妇无套高潮一二三区 | 国产一区二区在线播放 | 久久91精品久久久久久9鸭 | 中文字幕在线视频精品 | 久久伊人青青草 | 国产99久久精品一区二区永久免费 | 亚洲免费婷婷 | 一区二区三区免费 | 欧美一区视频 | 成人久久久 | 麻豆changesxxx国产 | 国产精品7777777 | 成人精品啪啪欧美成 | 国产伊人精品 |