English 中文(简体)
a-(Msql)
原标题:a SQL-(mysql) question about which method is better

我需要把一些东西放在我的数据库中,以便检查他们拥有的课程,但哪一种方法更好。

{

Table1
Rows: 
    studentID,
    lessonID,
    hasPerfectCourse,
    courseID,

}

{

Table1
Rows: 
    studentID,
    lessonID 

Table2
Rows: 
    studentID,
    hasPerfectCourse,
    courseID

}

and they both do the same thing, but I would like to know which one is better f或 perf或mance

EDIT so if the student passed all his exams he ll have a perfectcourse and will just get a courseid so it s possible to get all the lessons with that courseid and if the student doesn t have a perfectcourse, f或 example he/she still have lessons from the first year while he/she is in the third year with also some lessons from the second year hope I made myself understandable because i m not the best person to explain something :D /EDIT Greetz, Haroun

最佳回答

表 => ;参加人数较少=> 的概念;业绩较好导致“选桌”反家长。

我认为,你的目标是在设计中采用第5种正常形式,然后在适当的情况下根据建筑工程和建筑考虑进行脱热。

简言之,在一个表格中保留数据是否会导致各行之间数据(数据、而不是钥匙)的重复,或将不同实体/单独实体的财产合并为单一表格?

If you re really concerned about "getting it right", read up on the web about Normalisation :)

问题回答

我认为,你再次询问如何设计表格,这是否正确?

如果是的话,正确的做法是使数据库正常化。 实现正常化的主要想法是避免将非关键数据复制到数据库中。 为此,我建议,最正常的做法是,有这样一套表格:

CREATE TABLE students (id, ...);
CREATE TABLE courses  (id, ...);
CREATE TABLE schedules (student_id, course_id);

第三个表格经常被称作合并表格,用来表达许多与人的关系。 询问某一学生正在学习的课程,请:

SELECT * FROM schedules WHERE schedules.student_id = :student_id;

询问学生是否报名参加某一课程,请:

SELECT * FROM schedules WHERE schedules.course_id = :course_id;

与假体相反,我建议增加表格=1>更加正常化=>减少数据异常。 我还要说,合并费用本身并不昂贵,特别是如果你有正确的指数;在不破坏你的数据完整性或使你的数据库难以查询的情况下,有更好的改进业绩的方法。

通常更狭小的表格会更好。 此外,你还应担心以正常方式储存你的数据。 http://www.edbarlow.com/document/optimize.htm

你们首先必须列出你们所有变数的属性。 根据这一说法,你会形成一种新的 d子设计。 比如,课程名称取决于课程资格,学生名称取决于学生。 因此,你不把所有4个变量列入同一表格,而是将其分开。 这减少了les之间的 red余,也很容易处理无效价值。 这是第五个正常形式。 总是很容易就这些表格提出询问。

如果你不得不在表格上填写索引,也是有益的。 由于价值无效的变量可按指数计算。

我认为,在大多数情况下,你们必须考虑:

Less tables => less joins statements => better performance





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签