由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - Which design is better?
相关主题
A wield thing in Oracle DBAbout INSERT IGNORE
讨论:在SELECT中限制TOP N条纪录Another one
Re: How to find a duplicate record in Acsybase如何实现create table as (select *)
better solution for cross table query in sql?誰來解釋一下這是什麼原理
help about SQL for ACCESS新手学数据库一个简单题求助
urgent help! insert value into tableOne Q for DB expert
Which one is better?怎样在T-SQl中执行一条放在varchar中的命令
请教2个sql query 问题谁知道下面这段是什么意思(ABOUT CONSTRAINTS)
相关话题的讨论汇总
话题: studentid话题: classname话题: design话题: class话题: index
进入Database版参与讨论
1 (共1页)
s****e
发帖数: 282
1
Design a table managing students and classes that a student takes.
There are two ways:
1. Using a vector as a column. The number of bits is equal to the number of
classes. "1" means enrolling in a class. "0" means not.
StudentID Class-vector
100 00110100
101 11010000
2. Use class name as a column.
StudentID ClassName
100 class3
100 class4
100 class6
101 class1
101 class2
101 class4
The number of class is not fixed. So
B*****g
发帖数: 34098
2
2
Create 2 index

of

【在 s****e 的大作中提到】
: Design a table managing students and classes that a student takes.
: There are two ways:
: 1. Using a vector as a column. The number of bits is equal to the number of
: classes. "1" means enrolling in a class. "0" means not.
: StudentID Class-vector
: 100 00110100
: 101 11010000
: 2. Use class name as a column.
: StudentID ClassName
: 100 class3

s****e
发帖数: 282
3
Thanks.
How about the following two indexes:
1.
CREATE UNIQUE INDEX sid ON mytable (StudentID, ClassName)
This is for search like: SELECT * WHERE mytable.StudentID==100
2.
CREATE UNIQUE INDEX class ON mytable (ClassName, StudentID)
This is for search like: SELECT * WHERE mytable.ClassName==class2

【在 B*****g 的大作中提到】
: 2
: Create 2 index
:
: of

B*****g
发帖数: 34098
4
I think 1 is only good (compare to index(StudentID))for
SELECT StudentID, ClassName WHERE mytable.StudentID==100
But if you server is "strong", I think your design is good.

【在 s****e 的大作中提到】
: Thanks.
: How about the following two indexes:
: 1.
: CREATE UNIQUE INDEX sid ON mytable (StudentID, ClassName)
: This is for search like: SELECT * WHERE mytable.StudentID==100
: 2.
: CREATE UNIQUE INDEX class ON mytable (ClassName, StudentID)
: This is for search like: SELECT * WHERE mytable.ClassName==class2

n********6
发帖数: 1511
5
Yeah.
It's better to understand what are the most frequently used query.
If a lot of request for
SELECT StudentID, ClassName WHERE mytable.Student ID = 100
then it is good.

【在 B*****g 的大作中提到】
: I think 1 is only good (compare to index(StudentID))for
: SELECT StudentID, ClassName WHERE mytable.StudentID==100
: But if you server is "strong", I think your design is good.

j*****n
发帖数: 1781
6
figure out what is many-to-many relationship.
s****e
发帖数: 282
7
If I create index only on the first column, like:
CREATE INDEX sid ON mytable (StudentID)
The index will not be an unique index. The following query will return many
rows, right?
SELECT StudentID, ClassName WHERE mytable.Student ID = 100

【在 n********6 的大作中提到】
: Yeah.
: It's better to understand what are the most frequently used query.
: If a lot of request for
: SELECT StudentID, ClassName WHERE mytable.Student ID = 100
: then it is good.

1 (共1页)
进入Database版参与讨论
相关主题
谁知道下面这段是什么意思(ABOUT CONSTRAINTS)help about SQL for ACCESS
SQL-Help!urgent help! insert value into table
如何用SQL语句判断一个TABLE是否存在?Which one is better?
Special character in insert values请教2个sql query 问题
A wield thing in Oracle DBAbout INSERT IGNORE
讨论:在SELECT中限制TOP N条纪录Another one
Re: How to find a duplicate record in Acsybase如何实现create table as (select *)
better solution for cross table query in sql?誰來解釋一下這是什麼原理
相关话题的讨论汇总
话题: studentid话题: classname话题: design话题: class话题: index