数据库实验

实验1

(8)前面根据流程完成后,直到第八步,导入两个样例数据库,导入完成后

1
SHOW DATABASES;

看到数据库导入成功:
![[Pasted image 20260505145039.png]]
(9)根据要求进行四项完整性检查:
![[Pasted image 20260505145632.png]]
![[Pasted image 20260505145649.png]]
![[Pasted image 20260505145713.png]]
![[Pasted image 20260505145726.png]]
(10)备份
![[Pasted image 20260505171930.png]]
(11)导出和导入
![[Pasted image 20260505174454.png]]
(12)编写DDL:
![[Pasted image 20260505213306.png]]
对表的结构进行修改:
![[Pasted image 20260505212542.png]]
展示表的结构:
![[Pasted image 20260505212627.png]]
创建索引:
![[Pasted image 20260505212734.png]]
![[Pasted image 20260505213127.png]]
创建成功。
删除索引![[Pasted image 20260505213148.png]]
删除之后:
![[Pasted image 20260505213212.png]]
插入数据的ddl
![[Pasted image 20260507144047.png]]
![[Pasted image 20260507144437.png]]
插入成功,同时展示查询操作
接下来是删除,修改
![[Pasted image 20260507144743.png]]
![[Pasted image 20260507144918.png]]
视图的操作
![[Pasted image 20260507145746.png]]
![[Pasted image 20260507145806.png]]
实验任务5:
(1)![[Pasted image 20260507215215.png]]
(2)![[Pasted image 20260507215838.png]]
(3)
![[Pasted image 20260507215952.png]]
(4)
![[Pasted image 20260507220251.png]]
(5)![[Pasted image 20260507222211.png]]
(6)
![[Pasted image 20260507222323.png]]
(7)
![[Pasted image 20260507222923.png]]
(8)
![[Pasted image 20260507223413.png]]
(9)![[Pasted image 20260507223921.png]]
(10)我的表造的不符合要求,我就直接贴代码

1
2
3
4
SELECT COUNT(DISTINCT sno) 
FROM course
WHERE teacher = 'MARY';
//默认选课的记录都在course里面

![[Pasted image 20260507224941.png]]
(11)

1
2
3
SELECT reason, sname
FROM rest
WHERE statu = '审核未通过' AND teacher = 'XX';

![[Pasted image 20260507225047.png]]
(12)![[Pasted image 20260507230011.png]]

复杂查询

(1)
![[Pasted image 20260508202501.png]]
(2)
![[Pasted image 20260508203527.png]]
(3)
![[Pasted image 20260508203725.png]]
(4)
![[Pasted image 20260508204907.png]]
(5)
![[Pasted image 20260508205406.png]]
(6)
![[Pasted image 20260508210419.png]]
(7)
左连接可以看到所有的学生
![[Pasted image 20260508210912.png]]
(8)
![[Pasted image 20260508210924.png]]
(9)
自然连接:根据重名的去找匹配,同名的列自动去重,不匹配的行直接丢弃
左连接:同名的列默认全保留,同时保留左表的全部,右表不匹配的为NULL

任务7:

(1)![[Pasted image 20260509160406.png]]
![[Pasted image 20260509160418.png]]
(2)
![[Pasted image 20260509160857.png]]
(3)
![[Pasted image 20260509161712.png]]
修改前
![[Pasted image 20260509161746.png]]
设置触发器
![[Pasted image 20260509161831.png]]
触发条件
![[Pasted image 20260509161856.png]]
触发器生效

任务8

![[Pasted image 20260508215546.png]]

实验二

37ba0e9b-d16e-4e82-9dc4-43e6ae7af0ef

ER图

d715227b-340e-480b-9629-ab023455de4e

生产sql脚本

bda5abe5-f8c3-4639-9936-ebc025d47603

导入成功

实验3:

67606e18-7f48-4e77-8657-5955a663cf74

7e29d65a-64d2-4699-a735-e20e98ad36f8

f452c9e1-13ce-4491-99e0-283d9d779590

3fb907a9-1a4c-4c08-b6b7-ec2eed2e7451

d0abd708-f4dc-46cd-820d-df39b48bdcd9

5f91654b-0ad2-4569-a599-5d96526509cb

ad7994b9-f6f9-4561-baab-364331e62ed9

b036fd0a-f408-4c6c-bb6f-dbd6e4b69b0f

改为medium级别

4f945f84-3afa-4b20-b0ba-63a57536aac0

0843c2f1-915a-44d0-a878-211d04b06260

b5b6ed08-2543-4407-b7ad-9ac3d814e54f

67838616-39bd-4097-ae1d-0242a3821d6a

f1390f80-18b0-4bf9-8aa0-e0cee30df848

high级别

8bd87ddd-8164-4b56-9d42-dceee163db7e

5c8f23de-638f-4c88-98ab-93cb5e5743b6

e8747c7d-61e5-4e81-9d2b-e7da84c84bfc

实验四:

2a0620b9-db96-4651-ae41-9cde3da19c0e