创建学生S、课程C、老师T、学生成绩表SC:
相关的sql练习:https://blog.csdn.net/glgom/article/details/82900890
-- 学生信息表
CREATE TABLE S(
UUID VARCHAR(36) NOT NULL COMMENT '随机主键' PRIMARY KEY,
SID VARCHAR(36) NOT NULL COMMENT '学号,唯一' UNIQUE,
SNAME VARCHAR(30) COMMENT '学生姓名',
AGE INT COMMENT '年龄',
SEX VARCHAR(1) COMMENT '性别'
);
-- UNIQUE唯一约束
INSERT INTO S(UUID,SID,SNAME,AGE,SEX)
VALUES('121','002','盲僧',10,'2'),
('122','003','盖伦',20,'2'),
('123','005','迦娜',18,'1'),
('124','008','贾克斯',50,'2'),
('125','009','青钢影',22,'1'),
('126','006','韦鲁斯',22,'2'),
('127','011','菲奥娜',20,'1'),
('128','010','诺手',40,'2'),
('129','012','金克丝',17,'1'),
('130','013','洛',19,'2'),
('132','014','霞',19,'1'),
('133','016','赵信',22,'2'),
('134','020','娑娜',15,'1'),
('136','023','亚索',25,'2'),
('140','022','艾希',15,'1')
;
-- 添加单条数据
INSERT INTO S(UUID,SID,SNAME,AGE,SEX)
value("100","333","郭",25,"1")
;
-- 课程信息表
CREATE TABLE C(
CID VARCHAR(36) NOT NULL COMMENT '课程号,主键' PRIMARY KEY,
CNAME VARCHAR(60) COMMENT '课程名',
TID VARCHAR(36) COMMENT '教师编号'
);
INSERT INTO C(CID, CNAME, TID)
VALUES('001','数据结构','211'),
('002','语文','212'),
('005','数学','213'),
('010','物理','217'),
('021','化学','215'),
('011','生物','214'),
('033','英语','216')
;
-- 成绩表
CREATE TABLE SC(
SID VARCHAR(36) COMMENT '学生学号',
CID VARCHAR(36) COMMENT '课程编号',
SCORE DOUBLE COMMENT '成绩'
);
INSERT INTO SC(SID, CID, SCORE)
VALUES('002','001',99),
('002','002',65),
('002','005',84),
('002','010',59),
('002','011',48),
('002','021',87),
('002','033',88),
('003','001',79),
('003','002',78),
('003','005',84),
('003','010',68),
('003','011',84),
('003','021',89),
('003','033',88),
('005','001',68),
('005','002',79),
('005','005',91),
('005','010',65),
('005','011',87),
('005','021',93),
('005','033',77),
('008','002',77),
('008','005',84),
('008','010',84),
('008','011',85),
('009','010',78),
('009','011',95),
('009','021',56),
('009','033',77),
('011','001',78),
('011','002',87),
('011','005',95),
('011','010',68),
('011','011',94),
('011','021',93),
('020','001',59)
;
-- 教师表
CREATE TABLE T(
TID VARCHAR(36) NOT NULL COMMENT '教师编号' PRIMARY KEY,
TNANE VARCHAR(30) COMMENT '教师姓名'
)
;
INSERT INTO T(TID, TNAME)
VALUES('211','凯尔'),
('212','千钰'),
('213','克列'),
('214','易'),
('215','拉克丝'),
('216','卢锡安'),
('217','奎因')
;
ALTER table t CHANGE TNANE TNAME VARCHAR(30)