First, the database operation
CREATE Database db1 charset UTF8; View the database show Database;show the CREATE database db1; Select Database (); Delete database db1; ALTER DATABASE DB1 DB2 charset UTF8;
Ii. creation of tables and insertion of data
User table CREATE TABLE user (IDint, user Varcher ( -) notNULLUnique, pwd varcher ( +) notNULLforeign KEY (group_id) references Group (ID)); Add insert into User table (user,pwd,group_id) VALUES ('winter horse and yarn','123','1'), ('small sow with snow dish','123','1'), ('Northern Hara Chun-hee','123','2'), ("',"',"'); User Group table CREATE TABLE group (IDintprimary Key auto_increment, Group_name Varcher ( -) ); multiple-to-multiple table CREATE TABLE Class2teacher (IDintprimary Key auto_increment, class_idintNotNULL, teacher_idint, constraint Fk_class foreign key (class_id) referencesclass, constraint Fk_teacher foreign key (teacher_id) references teacher, unique (class_id,teacher_id)); Insert into Class2teacher (class_id,teacher_id) VALUES ("',"'), ("',"');
Third, table query
even table query Select from user inner join group on user.group_id=group.id; sub- query Select from wherein (Selectfromwhere group_name=' Dog-losing group ');
MySQL data command