我们想要做一个选课系统,所以建了一个student table 和一个course table, 还需要一个
enrollment table,请问这个table 要怎么建呢?
student table
$query = "CREATE TABLE student (
student_id INT(8) NOT NULL AUTO_INCREMENT,
first_name VARCHAR(20) NOT NULL,
last_name VARCHAR(20) NOT NULL,
sex VARCHAR(1) NOT NULL,
department VARCHAR (25) NOT NULL,
year_of_birth INT (4) NOT NULL,
student_id_number VARCHAR(15) NOT NULL,
password VARCHAR(30) NOT NULL,
email VARCHAR(15) NOT NULL,
introduction VARCHAR(200) NOT NULL,
PRIMARY KEY (student_id))";
create meal table
$query = "CREATE TABLE meal4 (
meal_id INT(8) NOT NULL AUTO_INCREMENT,
student_id_number VARCHAR(20) NOT NULL,
place VARCHAR(25) NOT NULL,
mealdate DATETIME DEFAULT NULL,
time_section VARCHAR(10) NOT NULL,
members VARCHAR(3) NOT NULL,
note VARCHAR(200) NOT NULL,
PRIMARY KEY (meal_id))";
create enrollment table
$query = "CREATE TABLE enrolment1 (
student_id INT(8) NOT NULL ,
meal_id INT(8) NOT NULL,
PRIMARY KEY (student_id))";
这样对吗?
你的問題是不會下create table的命令,還是不會設計?
建議先審視需求,然後做實體-關連的分析,最後才設計table。
從你提供的三個table看起來,有不少需求沒考慮清楚。