当前位置:网站首页>SQLSERVER database application and development: Chapter 9 computer operation
SQLSERVER database application and development: Chapter 9 computer operation
2022-06-10 22:36:00 【White in white】
Code and explanation
9.1:
create procedure StuInfo3
as
select studentno,sname,birthdate,phone
from student
where studentno like '18%'
go
exec StuInfo3
9.2
create procedure ScoreInfo
as
select student.studentno,sname,sex,cname,final
from student,course,score
where student.studentno=score.studentno and score.courseno=course.courseno
go
exec ScoreInfo
9.3
if exists(
select name from sysobjects
where name= 'stu_age' and type= 'p'
)
drop procedure stu_Age
go
create procedure stu_Age
@studentno nvarchar(10),@age int output
as
declare @errorvalue int
set @errorvalue=0
select @age=year(GETDATE())-year(birthdate)
from student
where studentno=@studentno
if(@@ERROR<>0)
set @errorvalue=@@ERROR
return @errorvalue
go
declare @average int
exec stu_age '1',@age=@average output
select @average
- procedure It's equivalent to a function , There are two parameters , You can set parameters in the function body , Set in the code @age= Age , Easy to return ;@studentno Used for matching
- @@error It's not equal to 0 There was an error , Error number returned
- @average Used to receive the returned @ave
- type='p’ Show as prodecure
9.4
create trigger stu_insert
on student
after insert
as
print ' You inserted a new record '
go
9.5
CREATE TRIGGER TR_ScoreCheck
ON score
FOR INSERT, UPDATE
AS
IF UPDATE(final )
PRINT 'AFTER The trigger starts executing ……'
BEGIN
DECLARE @ScoreValue real
SELECT @ScoreValue=(SELECT final FROM inserted)
IF @ScoreValue>100 OR @ScoreValue<0
PRINT ' Incorrect score entered , Please confirm the entered test score !'
END
GO
- insert and update Statement after the corresponding trigger is activated , All records added or updated are saved to inserted In the table
- delete and update Statement after the corresponding trigger is activated , All deleted records are saved to deleted In the table
- for amount to after
9.6
if exists(select name from sysobjects where name='dela' and type='tr')
drop trigger dela
go
create trigger dela
on course
after delete
as
print' Can't delete '
- type='tr’ Expressed as trigger
边栏推荐
- 【Py】接口签名校验失败可能是由于ensure_ascii的问题
- SQLServer数据库应用与开发:第九章上机
- 自己做了个相亲交友App,有兴趣的朋友可以看看
- 自己搞了一个相亲软件的源码,用兴趣的可以聊聊
- How to do well in the top-level design of informatization in the process of informatization upgrading of traditional enterprises
- 【TcaplusDB知识库】TcaplusDB进程启动介绍
- leetcode 130. Surrounded Regions 被围绕的区域(中等)
- 【TcaplusDB知识库】TcaplusDB引擎参数调整介绍
- README
- "The specified database user/password combination is rejected..." Solutions for
猜你喜欢

Tcapulusdb Jun · industry news collection (I)

【TcaplusDB知识库】TcaplusDB巡检统计介绍

Latex error: file ‘xxx.sty‘ not found

【TcaplusDB知识库】TcaplusDB查看线上运行情况介绍

Tcapulusdb Jun · industry news collection (VI)

Differences between disk serial number, disk ID and volume serial number

(11) Tableview

Icml2022 | sharp maml: model independent meta learning for sharpness perception

Visio 转为高质量PDF

How small and micro enterprises build micro official websites at low cost
随机推荐
LeetCode - 5. 最长回文子串
小微企业如何低成本搭建微官网
How to do well in the top-level design of informatization in the process of informatization upgrading of traditional enterprises
"The specified database user/password combination is rejected..." Solutions for
Record (II)
笔记(五)- JVM
JVM runtime data area
Visio to high quality pdf
datagrip 报错 “The specified database user/password combination is rejected...”的解决方法
重排 (reflow) 与重绘 (repaint)
Whale conference empowers intelligent epidemic prevention
Variables (automatic variables, static variables, register variables, external variables) and memory allocation of C malloc/free, calloc/realloc
torch_geometric
Notes (II)
Web3生态去中心化金融平台——Sealem Finance
Web3生态去中心化金融平台——Sealem Finance
[tcapulusdb knowledge base] tcapulusdb machine initialization and launch introduction
中小型会议如何进行数字化升级?
CCF CSP 202109-3 脉冲神经网络
【TcaplusDB知识库】TcaplusDB查看进程所在机器介绍