Goal: Create three tables, Student table student (Sid,name,gender), curriculum Course (cid,name), score mark (Mid, Sid, CID, gender);
Requires SID, Cid, and mid as the primary key,
Student name can only be F or M
The SID CID in Mark is a foreign key, and the combination is unique to ensure that each student can only have one score per course
Start terminal under Ubuntu
Start the MySQL service
sudo service MySQL start
Log in with the root account
Mysql-u root-p
Create a database
Create Database Student_system;
Open Database
Use Student_system;
Create student Tables
CREATE TABLE student (SID Int (primary) key, name Char (a), Gender enum (' F ', ' M '));
Create a curriculum
CREATE TABLE course (CID Int (ten) primary key, name Char (20));
Create a score table
CREATE table mark (mid int (ten) primary key, Sid Int (TEN), Cid Int (ten), score int,
Constraint Mark_sid foreign key (SID) references student (SID),
Constraint mark_cid foreign KEY (CID) References course (CID),
Unique Unique_sid_cid (SID, Cid));
MySQL Learning one: building tables