索引点关联册章节 问下搜索这个功能数据库应该怎么设计比较合理
31 个解决方案
#1
章节独立出一个表,再加一个关系表关联试题
#2
试题表
试题与章节表
章节属性表
试题与章节表
章节属性表
#3
首先谢谢,如果我需要对搜索结果集排序会不会比较难处理 这样取出数据只有题目id 然后到试题表里取出数据
这样理解对吗
#4
排序是需要基于什么信息?三个表是为了实现多对多,比如一个试题可能有多个属性,而一个属性可能又被多套试题所公用。通过三个表,可以获取试题和属性的相关信息,至于你的排序,先要知道你想拿出什么信息,然后“按什么来排”
#5
在题目里我有一个创建时间,一个星级主要这两个属性排列
#6
我给个大概的情况你看看,稍等
#7
我需要拿出试题表的题目内容
#8
谢谢
#9
试题(id,CONTENT,xxxx)
关系表(试题ID,属性ID)
属性表(id,属性名,排序规则)--排序规则你可以指定,比如创建日期的为1,星级为2等
SELECT *
FROM 试题 a INNER JOIN 关系表 b ON a.id=b.试题ID
INNER JOIN 属性表 c ON b.属性ID=c.id
ORDER BY c.排序规则
关系表(试题ID,属性ID)
属性表(id,属性名,排序规则)--排序规则你可以指定,比如创建日期的为1,星级为2等
SELECT *
FROM 试题 a INNER JOIN 关系表 b ON a.id=b.试题ID
INNER JOIN 属性表 c ON b.属性ID=c.id
ORDER BY c.排序规则
#10
你看看能不能看懂
#11
这样子的写和视图区别大吗
#12
视图下搜索特别慢
#13
视图实际上还是sql语句,慢有慢的原因,你贴出执行计划来看看,ctrl+m,然后执行你的语句,下面就会有一个图
#14
哦 ==
#15
b_examination 如果不能再加where条件的话,建个索引吧,把你的语句贴出来看看
#16
我用的是视图 视图语句如下
SELECT dbo.B_Course.CourseName, dbo.B_Examination.ExaminationID, dbo.B_Examination.CourseID, dbo.B_Examination.ExaminationType,
dbo.B_Examination.ExaminationName, dbo.B_Examination.ExaminationContent, dbo.B_Examination.ExaminationResult,
dbo.B_Examination.ExaminationRemark, dbo.B_Examination.IsDisable, dbo.B_Examination.ContentItem, dbo.B_Examination.ExaminationSource,
dbo.B_Examination.IsCheck, dbo.B_Examination.Difficulty, dbo.B_Examination.AnswerTime, dbo.B_Examination.CreateTime,
dbo.B_Examination.TeacherID, dbo.B_Examination.LastOpertaor, dbo.B_Examination.IdentID, dbo.B_Examination.UserCount,
dbo.B_Examination.UpdateTime, dbo.B_Examination.IncludeLabel, dbo.B_Examination.AverageStarLevel
FROM dbo.B_Course INNER JOIN
dbo.B_Examination ON dbo.B_Course.CourseID = dbo.B_Examination.CourseID
#17
不能再加点where条件了?
#18
如果不能再加,可能要用索引视图
#19
这样会不会好点?不过我觉得还是要加where条件为好
SELECT dbo.B_Course.CourseName ,
dbo.B_Examination.ExaminationID ,
dbo.B_Examination.CourseID ,
dbo.B_Examination.ExaminationType ,
dbo.B_Examination.ExaminationName ,
dbo.B_Examination.ExaminationContent ,
dbo.B_Examination.ExaminationResult ,
dbo.B_Examination.ExaminationRemark ,
dbo.B_Examination.IsDisable ,
dbo.B_Examination.ContentItem ,
dbo.B_Examination.ExaminationSource ,
dbo.B_Examination.IsCheck ,
dbo.B_Examination.Difficulty ,
dbo.B_Examination.AnswerTime ,
dbo.B_Examination.CreateTime ,
dbo.B_Examination.TeacherID ,
dbo.B_Examination.LastOpertaor ,
dbo.B_Examination.IdentID ,
dbo.B_Examination.UserCount ,
dbo.B_Examination.UpdateTime ,
dbo.B_Examination.IncludeLabel ,
dbo.B_Examination.AverageStarLevel
FROM dbo.B_Course
INNER HASH JOIN dbo.B_Examination ON dbo.B_Course.CourseID = dbo.B_Examination.CourseID
#20
=
== 我试试
== 我试试
#21
这样改了之后就不能加任何条件了吗
#22
可以啊,建议加上where条件,不然你这是全表扫描,性能好不了哪里去
#23
SELECT top 1000 dbo.B_Course.CourseName ,
dbo.B_Examination.ExaminationID ,
dbo.B_Examination.CourseID ,
dbo.B_Examination.ExaminationType ,
dbo.B_Examination.ExaminationName ,
dbo.B_Examination.ExaminationContent ,
dbo.B_Examination.ExaminationResult ,
dbo.B_Examination.ExaminationRemark ,
dbo.B_Examination.IsDisable ,
dbo.B_Examination.ContentItem ,
dbo.B_Examination.ExaminationSource ,
dbo.B_Examination.IsCheck ,
dbo.B_Examination.Difficulty ,
dbo.B_Examination.AnswerTime ,
dbo.B_Examination.CreateTime ,
dbo.B_Examination.TeacherID ,
dbo.B_Examination.LastOpertaor ,
dbo.B_Examination.IdentID ,
dbo.B_Examination.UserCount ,
dbo.B_Examination.UpdateTime ,
dbo.B_Examination.IncludeLabel ,
dbo.B_Examination.AverageStarLevel
FROM dbo.B_Course
INNER HASH JOIN dbo.B_Examination ON dbo.B_Course.CourseID = dbo.B_Examination.CourseID
where B_Examination.CourseID=5
条件不能这样加吗 加上会爆一个错误
由于此查询中定义了提示,查询处理器未能生成查询计划。请重新提交查询,并且不要在查询中指定任何提示,也不要使用 SET FORCEPLAN。
#24
先执行第一条建索引的语句,然后执行下面的SELECT语句,如果还慢,再贴执行计划给我看看
CREATE CLUSTERED INDEX IX_B_Examination ON B_Examination(CourseID)
SELECT TOP 1000
dbo.B_Course.CourseName ,
dbo.B_Examination.ExaminationID ,
dbo.B_Examination.CourseID ,
dbo.B_Examination.ExaminationType ,
dbo.B_Examination.ExaminationName ,
dbo.B_Examination.ExaminationContent ,
dbo.B_Examination.ExaminationResult ,
dbo.B_Examination.ExaminationRemark ,
dbo.B_Examination.IsDisable ,
dbo.B_Examination.ContentItem ,
dbo.B_Examination.ExaminationSource ,
dbo.B_Examination.IsCheck ,
dbo.B_Examination.Difficulty ,
dbo.B_Examination.AnswerTime ,
dbo.B_Examination.CreateTime ,
dbo.B_Examination.TeacherID ,
dbo.B_Examination.LastOpertaor ,
dbo.B_Examination.IdentID ,
dbo.B_Examination.UserCount ,
dbo.B_Examination.UpdateTime ,
dbo.B_Examination.IncludeLabel ,
dbo.B_Examination.AverageStarLevel
FROM dbo.B_Course
INNER JOIN dbo.B_Examination ON dbo.B_Course.CourseID = dbo.B_Examination.CourseID
WHERE B_Examination.CourseID = 5
#25
谢谢 我再试试
#26
加我关注吧...
#27
加上索引还是不行
还是同样的错误
#28
加关注。。。
#29
看到我私信没?
#30
看到了 3q
#31
#1
章节独立出一个表,再加一个关系表关联试题
#2
试题表
试题与章节表
章节属性表
试题与章节表
章节属性表
#3
首先谢谢,如果我需要对搜索结果集排序会不会比较难处理 这样取出数据只有题目id 然后到试题表里取出数据
这样理解对吗
#4
排序是需要基于什么信息?三个表是为了实现多对多,比如一个试题可能有多个属性,而一个属性可能又被多套试题所公用。通过三个表,可以获取试题和属性的相关信息,至于你的排序,先要知道你想拿出什么信息,然后“按什么来排”
#5
在题目里我有一个创建时间,一个星级主要这两个属性排列
#6
我给个大概的情况你看看,稍等
#7
我需要拿出试题表的题目内容
#8
谢谢
#9
试题(id,CONTENT,xxxx)
关系表(试题ID,属性ID)
属性表(id,属性名,排序规则)--排序规则你可以指定,比如创建日期的为1,星级为2等
SELECT *
FROM 试题 a INNER JOIN 关系表 b ON a.id=b.试题ID
INNER JOIN 属性表 c ON b.属性ID=c.id
ORDER BY c.排序规则
关系表(试题ID,属性ID)
属性表(id,属性名,排序规则)--排序规则你可以指定,比如创建日期的为1,星级为2等
SELECT *
FROM 试题 a INNER JOIN 关系表 b ON a.id=b.试题ID
INNER JOIN 属性表 c ON b.属性ID=c.id
ORDER BY c.排序规则
#10
你看看能不能看懂
#11
这样子的写和视图区别大吗
#12
视图下搜索特别慢
#13
视图实际上还是sql语句,慢有慢的原因,你贴出执行计划来看看,ctrl+m,然后执行你的语句,下面就会有一个图
#14
哦 ==
#15
b_examination 如果不能再加where条件的话,建个索引吧,把你的语句贴出来看看
#16
我用的是视图 视图语句如下
SELECT dbo.B_Course.CourseName, dbo.B_Examination.ExaminationID, dbo.B_Examination.CourseID, dbo.B_Examination.ExaminationType,
dbo.B_Examination.ExaminationName, dbo.B_Examination.ExaminationContent, dbo.B_Examination.ExaminationResult,
dbo.B_Examination.ExaminationRemark, dbo.B_Examination.IsDisable, dbo.B_Examination.ContentItem, dbo.B_Examination.ExaminationSource,
dbo.B_Examination.IsCheck, dbo.B_Examination.Difficulty, dbo.B_Examination.AnswerTime, dbo.B_Examination.CreateTime,
dbo.B_Examination.TeacherID, dbo.B_Examination.LastOpertaor, dbo.B_Examination.IdentID, dbo.B_Examination.UserCount,
dbo.B_Examination.UpdateTime, dbo.B_Examination.IncludeLabel, dbo.B_Examination.AverageStarLevel
FROM dbo.B_Course INNER JOIN
dbo.B_Examination ON dbo.B_Course.CourseID = dbo.B_Examination.CourseID
#17
不能再加点where条件了?
#18
如果不能再加,可能要用索引视图
#19
这样会不会好点?不过我觉得还是要加where条件为好
SELECT dbo.B_Course.CourseName ,
dbo.B_Examination.ExaminationID ,
dbo.B_Examination.CourseID ,
dbo.B_Examination.ExaminationType ,
dbo.B_Examination.ExaminationName ,
dbo.B_Examination.ExaminationContent ,
dbo.B_Examination.ExaminationResult ,
dbo.B_Examination.ExaminationRemark ,
dbo.B_Examination.IsDisable ,
dbo.B_Examination.ContentItem ,
dbo.B_Examination.ExaminationSource ,
dbo.B_Examination.IsCheck ,
dbo.B_Examination.Difficulty ,
dbo.B_Examination.AnswerTime ,
dbo.B_Examination.CreateTime ,
dbo.B_Examination.TeacherID ,
dbo.B_Examination.LastOpertaor ,
dbo.B_Examination.IdentID ,
dbo.B_Examination.UserCount ,
dbo.B_Examination.UpdateTime ,
dbo.B_Examination.IncludeLabel ,
dbo.B_Examination.AverageStarLevel
FROM dbo.B_Course
INNER HASH JOIN dbo.B_Examination ON dbo.B_Course.CourseID = dbo.B_Examination.CourseID
#20
=
== 我试试
== 我试试
#21
这样改了之后就不能加任何条件了吗
#22
可以啊,建议加上where条件,不然你这是全表扫描,性能好不了哪里去
#23
SELECT top 1000 dbo.B_Course.CourseName ,
dbo.B_Examination.ExaminationID ,
dbo.B_Examination.CourseID ,
dbo.B_Examination.ExaminationType ,
dbo.B_Examination.ExaminationName ,
dbo.B_Examination.ExaminationContent ,
dbo.B_Examination.ExaminationResult ,
dbo.B_Examination.ExaminationRemark ,
dbo.B_Examination.IsDisable ,
dbo.B_Examination.ContentItem ,
dbo.B_Examination.ExaminationSource ,
dbo.B_Examination.IsCheck ,
dbo.B_Examination.Difficulty ,
dbo.B_Examination.AnswerTime ,
dbo.B_Examination.CreateTime ,
dbo.B_Examination.TeacherID ,
dbo.B_Examination.LastOpertaor ,
dbo.B_Examination.IdentID ,
dbo.B_Examination.UserCount ,
dbo.B_Examination.UpdateTime ,
dbo.B_Examination.IncludeLabel ,
dbo.B_Examination.AverageStarLevel
FROM dbo.B_Course
INNER HASH JOIN dbo.B_Examination ON dbo.B_Course.CourseID = dbo.B_Examination.CourseID
where B_Examination.CourseID=5
条件不能这样加吗 加上会爆一个错误
由于此查询中定义了提示,查询处理器未能生成查询计划。请重新提交查询,并且不要在查询中指定任何提示,也不要使用 SET FORCEPLAN。
#24
先执行第一条建索引的语句,然后执行下面的SELECT语句,如果还慢,再贴执行计划给我看看
CREATE CLUSTERED INDEX IX_B_Examination ON B_Examination(CourseID)
SELECT TOP 1000
dbo.B_Course.CourseName ,
dbo.B_Examination.ExaminationID ,
dbo.B_Examination.CourseID ,
dbo.B_Examination.ExaminationType ,
dbo.B_Examination.ExaminationName ,
dbo.B_Examination.ExaminationContent ,
dbo.B_Examination.ExaminationResult ,
dbo.B_Examination.ExaminationRemark ,
dbo.B_Examination.IsDisable ,
dbo.B_Examination.ContentItem ,
dbo.B_Examination.ExaminationSource ,
dbo.B_Examination.IsCheck ,
dbo.B_Examination.Difficulty ,
dbo.B_Examination.AnswerTime ,
dbo.B_Examination.CreateTime ,
dbo.B_Examination.TeacherID ,
dbo.B_Examination.LastOpertaor ,
dbo.B_Examination.IdentID ,
dbo.B_Examination.UserCount ,
dbo.B_Examination.UpdateTime ,
dbo.B_Examination.IncludeLabel ,
dbo.B_Examination.AverageStarLevel
FROM dbo.B_Course
INNER JOIN dbo.B_Examination ON dbo.B_Course.CourseID = dbo.B_Examination.CourseID
WHERE B_Examination.CourseID = 5
#25
谢谢 我再试试
#26
加我关注吧...
#27
加上索引还是不行
还是同样的错误
#28
加关注。。。
#29
看到我私信没?
#30
看到了 3q