当前位置:网站首页>SQL -- course experiment examination
SQL -- course experiment examination
2022-06-12 07:13:00 【Not Agan】
《 Database principle experiment 》
Course examination report
1、 Simple requirements
The main function of this system is to collect students' personal information , Teachers' teaching situation . System
The main functions of :
a、 Student personal information includes : full name 、 Student number .
b、 The elective list includes : Student number 、 Course no. 、 achievement .
c、 The curriculum includes : Course no. 、 Course name 、 Teacher number 、 Teacher number .
d、 A trigger : Users are prohibited from inserting scores less than 0 Student information
e、 Two stored procedures :① Find the average score of the specified subject ② Reduce the scores of designated students
2、 Conceptual structural design

chart 1 E-R chart
3、 The structure of the design table



chart 2 The structure of the table
4、 Create database
① Build table
ifOBJECT_ID('Student')isnotnull
droptable Student
go
createtable Student
(
Sno char(9)primarykey,
Sname char(9)notnullunique,
);
go
ifOBJECT_ID('Course')isnotnull
droptable Course
go
createtable Course
(
Cno char(2)primarykey,
Cname char(20)notnull,
Tno char(9)notnull,
Tname char(9)notnull,
);
go
ifOBJECT_ID('SC')isnotnull
droptable SC
go
createtable SC
(
SC_Sno char(9),
SC_Cno char(2),
SC_Grade intnull,
primarykey(SC_Sno,SC_Cno),
foreignkey(SC_Sno)references Student(Sno),
foreignkey(SC_Cno)references Course(Cno)
);
Go

chart 3 design sketch
② Create triggers and stored procedures
-- trigger
ifOBJECT_ID('tri_SC')isnotnull
droptrigger tri_SC
go
createtrigger tri_SC on SC
afterinsert
as
declare @temp int,@SNo char(9),@CNo char(2)
set @temp =(selecttop 1 SC_Grade from inserted)
set @CNo =(selecttop 1 SC_Cno from inserted)
set @SNo =(selecttop 1 SC_Sno from inserted)
if(@temp>=0)
begin
print' Insert the success '
end
else
begin
deletefrom SC where(SC_Sno like @SNo and SC_Cno like @CNo)
print' The score is less than 0 Do not insert '
end
go
-- stored procedure 1
ifOBJECT_id('reduce')isnotnull
dropprocedure avgGrade
go
createprocedure reduce(@num int,@sno char(9),@cno char(2))
asdeclare
@finalGrade int;
begin
set @finalGrade =(select SC_Grade from SC where (SC_Sno like @sno and SC_Cno like @cno))
update SC
set SC_Grade = @finalGrade-@num
where (SC_Sno like @sno and SC_Cno like @cno)
end
-- stored procedure 2
ifOBJECT_id('avgGrade')isnotnull
dropprocedure avgGrade
go
createprocedure avgGrade(@cno char(2))
as
begin
selectavg(SC_Grade)
from SC
groupby(SC_Cno)
having SC_Cno like @cno
end
5、 Verification function
① insert data
insert
into Student(Sno,Sname)values
('20041013',' Agan '),
('20049014',' Infinite '),
('20049015',' Little black '),
('20041016',' Wind breath ');
go
insert Course(Cno,Cname,Tno,Tname)values
('1',' database ','1111',' Mr. Xing '),
('2',' mathematics ','1111',' Mr. Xing '),
('3',' Network counting ','1111',' Mr. Xing '),
('4',' Physics ','1111',' Mr. Xing '),
('5','C Language ','1112',' Infinite teacher ');
go
insert SC(SC_Sno,SC_Cno,SC_Grade)values
('20041013','1',100),
('20041013','2',100),
('20041013','3',100),
('20041013','4',100),
('20041016','1',90),
('20041016','2',100);
go



chart 4 Result chart
③ Trigger validation
Try inserting a score less than 0 Student information .
insert SC(SC_Sno,SC_Cno,SC_Grade)values
('20041016','3',-1)

chart 5 Trigger result graph
④ Storage process
reduce stored procedure : Reduce student number 20041013 Student subject 1 fraction 20
exec reduce@num=20,@sno='20041013',@cno='1';

chart 6 Stored procedure result graph
avgGrade stored procedure : Demand account 1 On average
exec avgGrade@cno='1';-- Demand account cno 1 On average

chart 7 Stored procedure result graph
边栏推荐
- Lambda function perfect use guide
- Unable to load bean of class marked with @configuration
- 库里扛起了勇士对凯尔特人的第四场
- libprint2
- RT thread studio learning (x) mpu9250
- Pyhon的第五天
- 新知识:Monkey 改进版之 App Crawler
- I met 15 people recently and found that I couldn't answer the basic question of this test
- 5 lines of code identify various verification codes
- 报表工具的二次革命
猜你喜欢
![Leetcode: Sword finger offer 67 Convert string to integer [simulation + segmentation + discussion]](/img/32/16751c0a783cc3121eddfe265e2f4f.png)
Leetcode: Sword finger offer 67 Convert string to integer [simulation + segmentation + discussion]

RT thread studio learning (I) new project

Throw away the ugly toast. The movable toast is more interesting

新知识:Monkey 改进版之 App Crawler

Scons编译IMGUI

1. Foundation of MySQL database (1- installation and basic operation)

Detailed explanation of coordinate tracking of TF2 operation in ROS (example + code)

Kali and programming: how to quickly build the OWASP website security test range?

Pyhon的第六天

lambda 函数完美使用指南
随机推荐
(14) The software version number is displayed in the flash window of blender source code analysis
Junior high school education, less than 3k, to 30k+ monthly salary, how wonderful life is without restrictions
6 functions
5、 El expression & JSTL tag library
Summary of software testing tools in 2021 - unit testing tools
Kotlin plug-ins kotlin Android extensions
Explain in detail the use of dynamic parameter adjustment and topic communication in ROS (principle + code + example)
LED lighting experiment with simulation software proteus
sql——课程实验考查
8086/8088 instruction execution pipeline disconnection reason
Demonstrate "topic communication, action communication, service communication and parameter server" with a small turtle case
d不能用非常ctfe指针
Scons编译IMGUI
JDE 对象管理工作平台介绍及 From 的使用
A journey of database full SQL analysis and audit system performance optimization
Imx6q pwm3 modify duty cycle
Dynamic coordinate transformation in ROS (dynamic parameter adjustment + dynamic coordinate transformation)
【图像去噪】基于非局部欧几里德中值 (NLEM) 实现图像去噪附matlab代码
Category 7
ROS dynamic parameter configuration: use of dynparam command line tool (example + code)