【发布时间】:2017-01-31 19:33:00
【问题描述】:
我正在尝试使用索引,但我还是新手。假设我经常使用以下查询,所以我需要为表 music 和 musicians 创建索引。
SELECT *
FROM music
where musician_id = @id
SELECT *
FROM music
where musician_id = @id and date_of_birth > @date
SELECT *
FROM music
where date_of_birth > @date1 and date_of_birth < @date2
SELECT first_name, last_name, musician_website
FROM musicians
where last_name = @last_name
SELECT customer_id, first_name, last_name,musician_website
FROM musicians
where last_name = @last_name and musician_website= @site
如果我想为这些查询创建索引,您认为最好的解决方案是什么。最好为我想要的每一列制作一个(例如 1 个用于musician_id,一个用于date_of_birth 等...)或者可能将它们成对使用:musician_id 和date_of_birth,然后@ 987654329@ 和 musician_website 然后只是 date_of_birth 用于第三个查询(我需要它们按日期排序)。
在这里最好的选择是什么?为什么?
【问题讨论】:
-
至少包括表模式...为什么
music有date_of_birth?我们应该猜到您打算在其中包含一个联接吗? -
不,这只是表的一个坏名字。餐桌音乐包含有关音乐家和出生日期的信息。
-
听起来你需要在索引之前担心normalization。
-
是的,谢天谢地,我正处于项目的开始阶段。感谢您指出这一点。
标签: sql sql-server database indexing