数据库原理与应用第四版(何玉洁)p45~46的数据库建库代码

纯手打,求点赞!

Code:

CREATE DATABASE Student;
USE Student;

CREATE TABLE Student (
	Sno INT PRIMARY KEY,
    Sname VARCHAR(20) NOT NULL,
    Ssex VARCHAR(1),
    Sage INT,
    Sdept VARCHAR(10)
);
alter table Student change Sname Sname varchar(20) character set utf8;
alter table Student change Ssex Ssex varchar(1) character set utf8;
alter table Student change Sdept Sdept varchar(10) character set utf8;

INSERT INTO Student(Sno, Sname, Ssex, Sage, Sdept) VALUES
(1512101, '李勇', '男', 19, '计算机系'),
(1512102, '刘晨', '男', 20, '计算机系'),
(1512103, '王敏', '女', 18, '计算机系'),
(1512104, '李小玲', '女', 19, '计算机系'),

(1521101, '张立', '男', 22, '信息系'),
(1521102, '吴斌', '女', 21, '信息系'),
(1521103, '张海', '男', 20, '信息系'),

(1531101, '钱小平', '女', 18, '数学系'),
(1531102, '王大力', '男', 19, '数学系');

CREATE TABLE Course (
    Cno VARCHAR(4) PRIMARY KEY,
    Cname VARCHAR(6) NOT NULL,
    Credit INT,
    Semester INT
);
alter table Course change Cname Cname varchar(6) character set utf8;

INSERT INTO Course(Cno, Cname, Credit, Semester) VALUES
('c001', '计算机文化学', 3, 1),
('c002', '高等数学', 6, 1),
('c003', '高等数学', 3, 2),
('c004', '大学英语', 6, 2),
('c005', 'Java', 2, 3),
('c006', '程序设计', 3, 3),
('c007', '数据结构', 5, 4),
('c008', '操作系统', 4, 4),
('c009', '数据库基础', 4, 5),
('c010', '计算机网络', 5, 6);

CREATE TABLE SC (
    Sno INT NOT NULL,
    Cno VARCHAR(4) NOT NULL,
    Grade INT
);

INSERT INTO SC(Sno, Cno, Grade) VALUES
(1512101, 'c001', 90),
(1512101, 'c002', 86),
(1512101, 'c003', 92),
(1512101, 'c005', 88),
(1512101, 'c006', NULL),
(1512102, 'c001', 76),
(1512102, 'c002', 78),
(1512102, 'c005', 66),
(1512104, 'c002', 66),
(1512104, 'c005', 78),
(1512104, 'c008', 66),
(1521102, 'c001', 82),
(1521102, 'c005', 78),
(1521102, 'c007', 92),
(1521102, 'c009', 50),
(1521103, 'c002', 68),
(1521103, 'c006', NULL),
(1521103, 'c007', NULL),
(1521103, 'c008', 78),
(1531101, 'c001', 80),
(1531101, 'c005', 50),
(1531101, 'c007', 45),
(1531102, 'c001', 80),
(1531102, 'c002', 75),
(1531102, 'c005', 85),
(1531102, 'c009', 88);

你可能感兴趣的:(杂项)