SQL效率提公升之一些SQL編寫建議並有效利用索引

2022-09-25 03:42:10 字數 517 閱讀 4334

1.日期屬性列,不會因為有分秒差別而減慢查詢速度

2. 使用like比較進行查程式設計客棧詢時,如果模式以特定字串如「abc%」開頭,使用索引則會提高效率;如果模式以萬用字元如「%xyz」開頭,則索引不起作用

3. or會引起全表掃瞄,且和in的作用相當

4. 盡量少用not

5. exists 和 in的執行效率是一樣的

6. 用函式charindex()和前面加萬用字元%的like執行效率一樣

7. union並不絕對比or的執行效率高

8. www.cppcns.com欄位提取要按照「需多少、提多少」的原則cnkcho,避免「select *」

9. count(*)不比count (字段)慢

10. order by程式設計客棧按聚集索引列排序效率最高

11. 多用「top」進行資料提取,可提高效率

本文標題: sql效率提公升之一些sql編寫建議並有效利用索引

本文位址: /shujuku/mssql/56389.html

一些sql語句

一。在oracle中建表,怎麼實現id自動編號 1 建表 create table code test id int,name varchar2 20 2.建立序列 create sequence s country id increment by 1 start with 1 maxvalue 9...

一些常用SQL

1 對select 查詢出來的資料時行修改.1 select t.rowid,t.fromtablename t 取出資料物理rowid 並顯示,些時可以對其進行修改.2 select fromtablenamefor update 取出資料顯示,此時可以對其進行編輯.以上兩種修改,修改後一定要進行...

一些Sql語句

case when xx then yy else zz 例 case when count is null then 0 else count 當count為空的時候賦值0,不為空則取原值 isnull express1,express2 例 isnull count,0 當count為空的時候則...