当前位置:网站首页>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
边栏推荐
- D
- lambda 函数完美使用指南
- 网络丢包问题排查
- Unable to load bean of class marked with @configuration
- Noi openjudge computes the n-th power of 2
- 如何更新 Kubernetes 证书
- Matlab 6-DOF manipulator forward and inverse motion
- Summary of software testing tools in 2021 - unit testing tools
- RT thread studio learning (VII) using multiple serial ports
- Win10 list documents
猜你喜欢

esp32 hosted

leetcode.39 --- 组合总和

Pyhon的第五天

I met 15 people recently and found that I couldn't answer the basic question of this test

Dynamic coordinate transformation in ROS (dynamic parameter adjustment + dynamic coordinate transformation)

Node, topic, parameter renaming and global, relative and private namespaces in ROS (example + code)

RT thread studio learning (x) mpu9250

Test left shift real introduction

Some operations of MATLAB array

Descscheduler secondary scheduling makes kubernetes load more balanced
随机推荐
Leetcode: Sword finger offer 63 Maximum profit of stock [record prefix minimum and or no brain segment tree]
Kali与编程:如何快速搭建OWASP网站安全实验靶场?
Source code learning - [FreeRTOS] privileged_ Understanding of function meaning
What is the difference between < t > and object?
Detailed principle of 4.3-inch TFTLCD based on warship V3
12.13-12.19 summary
Beginners can't tell the difference between framework and class library
PowerDesigner connects to entity database to generate physical model in reverse
Nine project management issues that PM should understand
最近面了15个人,发现这个测试基础题都答不上来...
基于eNSP加防火墙的千人中型校园/企业网络规划与设计(附所有配置命令)
RT thread studio learning (VIII) connecting Alibaba cloud IOT with esp8266
Category 7
新知识:Monkey 改进版之 App Crawler
5 ROS simulation modeling (4-navigation navigation simulation)
Summary from November 29 to December 5
New knowledge: monkey improved app crawler
【图像去噪】基于高斯滤波、均值滤波、中值滤波、双边滤波四种滤波实现椒盐噪声图像去噪附matlab代码
[data clustering] data set, visualization and precautions are involved in this column
Class as a non type template parameter of the template