Primary key: Primary key A table has a single primary key, and the key value can be unique. You can set the primary key to self-increment.
Foreign key: Represents the related relationship between two relationships. A table with a foreign key of another relationship as the primary key is called the primary table, and a table with a key in it is called the primary table from the table.
Self-increment: CREATE TABLE t1 (ID int primary key auto_increment,name char (10));
CREATE tableclass(CID int primary key auto_increment,caption char (20) notnull); #创建class表 Insert intoclass(caption) VALUES ('three-year Class II'),('Three shifts a year'),('one class for three years'); #插入班级数据 CREATE TABLE student (SID int primary key Auto_increment,sname char (20) notNull,gender enum ('male','female'), class_id int notNull,constraint foreign KEY (class_id) referencesclass(CID) on the DELETE cascade on UPDATE cascade) #创建学生表, class ID associated to the class table Cidinsert into student (sname,gender,class_id) v Alues ('Steel Egg','female', 1), ('Steel Hammer','female', 1), ('Shanbao','male', 2) #插入数据create table teacher (tid int primary key Auto_increment,tname char (20) notnull); Insert into teacher (Tname) VALUES ('Puerto'),('Cang Jing'),('Rice Island Love'), CREATE TABLE course (CID int primary key Auto_increment,cname char (20) notnull,teach_id int notnull,constraint foreign KEY (teach_id) References teacher (tid) on DELETE cascade on UPDATE cascade), insert INTO course (cname,teach_id) VALUES ('Biological', 1), ('Sports', 1), ('Physical', 2CREATE TABLE score (SID int primary key auto_increment,student_id int notnull,course_id int notNull,number Int (3) notnull,constraint foreign KEY (student_id) references student (SID) on DELETE cascade on update Cascade,constraint Foreig N Key (course_id) References course (CID) on DELETE cascade on UPDATE cascade), insert into course values (1,1,1,60), (2,1,2,59), (3,2,2,100);
"Day2" MySQL primary key, foreign key, self-increment