我有這兩張表:
orders
order_id, customer_id, order_date, product_id, order_quantity
products
product_id, ProductName, SupplierID, UnitPrice, UnitsInStock
order_id并且product_id是主鍵。
我想根據這些定期執行的查詢創建索引
SELECT *
FROM orders
WHERE product_id = @id
SELECT *
FROM orders
WHERE customer_id = @id AND order_date > @date
SELECT *
FROM orders
WHERE order_date > @date1 AND order_date < @date2
SELECT product_id, ProductName, UnitsInstock
FROM products
WHERE UnitsInstock < @units
SELECT *
FROM products
WHERE ProductName = @name AND SupplierID = @Id
我對如何創建這些索引感到困惑,因為我不確切知道“@”符號在 SQL 中的作業原理以及如何在帶有 where 子句陳述句的索引中實作它。任何幫助將不勝感激!
uj5u.com熱心網友回復:
引數與索引無關。索引基于您在 WHERE 子句中使用較多的列。在第一個表中您使用更多:product_id customer_id order_date 在第二個表中您使用更多:UnitsInstock ProductName SupplierID
您可以在此列上添加索引,但請記住索引有利于查詢表,但不利于在表中插入和更新(插入/更新速度較慢)。
另一方面,@field 只是引數(您可以將其視為變數)在腳本的其他部分中,此引數正在獲取值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/418514.html
標籤:
上一篇:使用STE更新記錄
下一篇:如何使用引數在訪問表中添加行?
