Creative Library
Create DATABASE lianx1 DEFAULT Character Set UTF8
Table ################################
int, data type, representing integer
Not NULL means cannot be empty
Auto_increment indicates that the self-increment
PRIMARY key denotes primary key
Constraint foreign Key Name foreign key (the column to be associated) references the associated table (the associated column);
Create a class table
CREATE TABLE Class (
CID int NOT NULL auto_increment PRIMARY key,
Caption Char (32));
Create student Tables
CREATE TABLE Student (
Sid int NOT NULL auto_increment PRIMARY key,
Sname Char (32),
Gender char (32),
class_id int NOT NULL,
Constraint stu1 foreign KEY (class_id) references Class (CID));
Create a teacher table
CREATE TABLE Teacher (
TID int not NULL auto_increment PRIMARY KEY,
Tname Char (32));
Create a curriculum
CREATE TABLE Course (
CID int NOT NULL auto_increment PRIMARY KEY,
CNAME char (32),
tearch_id int NOT NULL,
Constraint Cour1 foreign KEY (tearch_id) References teacher (TID));
Create a score table
CREATE TABLE Score (
Sid int NOT NULL auto_increment PRIMARY KEY,
student_id int,
corse_id int,
Number char (32),
Constraint Score1 foreign KEY (student_id) references student (SID),
Constraint Score2 foreign KEY (corse_id) References course (CID));
Python-day11-mysql Database and Data sheet