50 SQL statements (MySQL version) create tables to insert data

This semester is learning database. Some time ago, the teacher asked us to do 50 classic SQL statements. At that time, we did it faster. Some of them were Baidu's, and we didn't understand them very well.

So from the beginning of this essay, I will make 50 copies of classic SQL statements to deepen my understanding.

The answer is for reference only, not necessarily completely right. If you find mistakes or have better ones, welcome to comment, communicate with each other and grow together!!!

--------------------------Table structure--------------------------

student(StuId,StuName,StuAge,StuSex) student table

teacher(TId,Tname) teacher table

Course (CID, CNAME, C? TID)

SC (SID, s-ciu, score) score sheet


Table building:

create database MySchool character set "utf8mb4";
use MySchool;
create table student
    StuId varchar(5) primary key,
    StuName varchar(10) not null,
    StuAge int,
    StuSex char(2) not null
create table teacher
    TId varchar(3) primary key,
    Tname varchar(10) not null
create table course
    CId varchar(3) primary key,
    Cname varchar(20) not null,
    C_TId varchar(3) not null,
create table sc
    SId varchar(5) not null,
    FOREIGN KEY (SId) REFERENCES student(StuId),
    S_CId varchar(3) not null,
    Score float

Insert data:

insert into student value('1000','zhang wuji',18,'male'),
('1001','Zhou Zhiruo',19,'female'),
('1002','Yang Guo',19,'male'),
('1003','Zhao Min',18,'female'),
('1004','little dragon maiden',17,'female'),
('1005','Zhang Sanfeng',18,'male'),
('1006','linghu chong',19,'male'),
('1007','Ren yingying',20,'female'),
('1008','Yue Lingshan',19,'female'),
('1010','Kang min',17,'female'),
('1011','Xiao Feng',19,'male'),
('1012','Huang Rong',18,'female'),
('1013','Guo Jing',19,'male'),
('1014','Zhou Botong',19,'male'),
('1015','Ying Gu',20,'female'),
('1016','Li Qiushui',21,'female'),
('1017','pharmacist hwang',18,'male'),
('1018','Li Mochou',18,'female'),
('1019','Feng Mufeng',17,'male'),
('1020','wang chongyang',17,'male'),
('1021','Guo Xiang',18,'female');

insert into teacher value('001','Yao Ming'),
('002','Ye Ping'),
('003','Ye Kai'),
('004','Meng Xinghun'),
('005','Seeking defeat alone'),
('006','Qiu Qianren'),
('007','Qiu micrometer'),
('008','Zhao Zhijing'),
('010','Guo Furong'),
('011','Tong Xiangyu'),
('012','White Hall'),
('013','LV Qinghou'),
('014','Li Dazui'),
('015','There is no shortage of flowers'),
('016','Gold does not change'),

insert into course value('001','business management','002'),
('004','data base','007'),
('005','logical circuit','006'),
('007','electronic circuit ','005'),
('008','Introduction to thought','004'),
('009','History of Western Philosophy','012'),
('010','linear algebra','017'),
('011','Fundamentals of computer','013'),
('012','AUTO CAD Drafting','015'),
('013','Graphic Artist Designer','011'),
('014','Flash Comic','001'),
('015','Java Development','009'),
('017','Oracl Database principle','010');

insert into sc value('1001','003',90),

Tags: MySQL Database SQL Java

Posted on Sun, 03 May 2020 17:30:28 -0400 by ambivalent