《MySQL数据库实用教程(附微课)课堂案例数据库的创建命令.docx》由会员分享,可在线阅读,更多相关《MySQL数据库实用教程(附微课)课堂案例数据库的创建命令.docx(3页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、复制下面的全部命令,登录MysQL数据库后,在,ysql”提示符下直接粘贴执行,将创建数据库scorcdb 以及该数据库中的6张表和完整性约束,同时写入所有的记录数据。DROP DATABASE IF EXISTS scoredb;CREATE DATABASE scoredb;USE scoredb;CREATE TABLE department ( deptno CHAR (3) NOT NULL PRIMARY KEY , deptname VARCHAR (50) UNIQUE, director VARCHAR(50) );CREATE TABLE student ( sno CHA
2、R (12) NOT NULL PRIMARY KEY, sname VARCHAR(50), sex CHAR(l) DEFAULT 男, birthdate DATE, party VARCHAR(50), classno VARCHAR(20), deptno CHAR(3), enterscore INT, awards TEXT ); create table course ( eno CHAR(8) NOT NULL PRIMARY KEY, cname VARCHAR(50), hours TINYINT ); create table teacher(tno CHAR (8)
3、NOT NULL PRIMARY KEY, tname VARCHAR(50), sex CHAR(l), title VARCHAR(5), deptno CHAR(3) );CREATE TABLE score ( sno CHAR(12) NOT NULL, eno CHAR(8) NOT NULL, grade TINYINT, schoolyear CHAR(9), semester CHAR(l), PRIMARY KEY (sno, eno) );CREATE TABLE teaching ( classno VARCHAR(20) NOT NULL, tno CHAR(8),
4、eno CHAR(8),PRIMARY KEY (classno, tno, eno);ALTER TABLE studentADD FOREIGN KEY (deptno) REFERENCES department(deptno)ON UPDATE CASCADE;ALTER TABLE teacherADD FOREIGN KEY (deptno) REFERENCES department(deptno)ON UPDATE CASCADE;ALTER TABLE scoreADD FOREIGN KEY(sno) REFERENCES student(sno)ON UPDATE RES
5、TRICTON DELETE RESTRICT;ALTER TABLE scoreADD FOREIGN KEY (eno) REFERENCES course (eno)ON DELETE CASCADE;ALTER TABLE teaching ADD FOREIGN KEY(tno) REFERENCES teacher (tno);ALTER TABLE teaching ADD FOREIGN KEY (eno) REFERENCES course (eno);ALTER TABLE department MODIFY director VARCHAR(50) DEFAULT 院长;
6、ALTER TABLE student ADD CHECK (sex IN (男,女);INSERT INTO departmentVALUES (101,外国语学院,李大国),(102,可再生能源学院,张国庆,),(103,能源动力与机械工程学院,王莱),(,104,电气与电子工程学院,马逖),(105,经济与管理学院,周海明),(T06,控制与计算机工程学院,姜尚),(T07,数理学院董蔚来),(108,新能源学院,孙磊仕);INSERT INTO student宋洪博,男,2003-05-15,,党员,英语 2101101, 698/ 三好学生, 一等奖学金),,刘向志,男,2002T0
7、-08,团员,英语 2101101, 625,李媛媛,女,2003-09-02团员英语 2102101, 596,),王琦,男,2003-01-23,团员,机械 2101103, 600,优秀学生干部,二等 奖学金),(张虎,男】2003-07-18,群众,机械 2104, T03, 650,北京市数学建模一等 奖),(T20211040101,王晓红,女,2002-09-02,团员电气 2101, 104, 630,),李明,男,2002-12-27,党员,电气 2101104, 650,李华,女,2003-01-Or ,,团员,电气 2111104, 648,侯明斌男,2002-12-03
8、,J党员,电气 2111104, 617,),(,张函,女,2003-03-07,团员,财务 2101105, 663,C ,/ 唐明卿,女,2002-10-15,群众,财务 2101105, 548/ 国家二级运动员),王刚,男,2004-01-12,团员,计算 2101106, 678,赵壮,男,2003-03-13,团员,计算 2102, 106, 605,李淑子,女,2003-06-14,党员,物理 2101107, 589,),刘丽,女,2002-11-17,团员,物理 2101107, 620/3,(,戴明明,男,2003-01-15, / 团员,水电 210T , 108, 61
9、0,);INSERT INTO courseVALUES C 10101400, / 学术英语,64),(10101410,通用英语,48),(10300710,现代控制理论,40),(10400350,模拟电子技术基础,56),(10500131,证券投资学,32),(10600200,高级语言程序设计,56),(10600450,无线网络安全,32),(10600611,数据库应用,56),(10700053,大学物理,56),(10700140,高等数学,64),(T0700462,线性代数,48);INSERT INTO teacher)z !7 5 !7 !/ 11 Qu 17 11
10、 17 17 7. 17 o o o o 114 566117 11 受 1 T- , , , 二二T , , , , , 授授,教,师师, 教教授副授师讲讲授 教/教讲教 , FTTr , , , 罗科,丽w明彦, 家江达晓平丽亚凯军 周宋林赵王马李孟朱VALUES ( 10100391,杨丽,女,副教授,TOI), (10112583, (10309242, (10423769, (10501561, (10610910, (10611295, (10631218, (10701274, (10710050,INSERT INTO score,-,,10500131,, / 1050013
11、T, 77, 45/ 2021-20222), (T2021106010410700140, 95, 2021 -2022, T), 85,2021-2022, 1), C ,),10700140, 66/ 2021-2022, 1);INSERT INTO teachingVAI.UES (英语 2101, 10100391, 10101400), (财务 210110100391, 10101400), (英语 2102, 10112583, 10101400), (财务 2101,1011258310101410), (电气 2111, 10309242,10300710), (物理 2
12、1011042376910400350), (电气 2111, 10423769, 10400350), (电气 2H1, 10501561, T0500131), (英语 210110501561, 10500131), (英语 21021050156110500131), (财务 21011050156110500131), (英语 2101, 10610910, 10600611), (英语 2102, 10610910, 10600611), (财务 210110610910, 10600200), (电气 2111, 10611295,10600200), (财务 2101, 106
13、11295, 10600611), (机械 2101, 10631218, 10600611), (电气 2111, 10631218, 106006H), (物理 210110701274, T0700140), (电气 2111, 10701274, 10700053), (计算 2101, 1070127410700053), (计算 21011070127410700140), (财务 21011070127410700140), (机械 2101, 10710050, 10700053), (机械 21011071005010700140), (电气 2H1, 10710050, T0700140), (英语 2101, 1071005010700140), (英语 21021071005010700140);