手机版

sql完整数据库操作、存储过程、登录判断,增删改(3)

发布时间:2021-06-05   来源:未知    
字号:

完整的数据库代码,实现小型数据库的所有功能,包括登录判断,注入式攻击,存储过程。。。。。。。。。

59
print '学生1001成绩全部及格'
else print '学生1001有成绩不及格'

--为表创建具有不同字段名的视图
create view v_stu(sid,sname,sex)
as
select sid,sname,sex from student
--查看视图数据
select * from v_stu

--使用存储过程实现从表及联删除
alter proc sp_delete
@sid int
as
delete from score where sid = @sid
delete from student where sid = @sid

exec sp_delete 1001
--使用存储过程添加学生信息
-------------------添加---------------------------------------开始-------------------------------------------------------------------------
alter proc sp_add
@sid int,
@sname nvarchar(20),
@sex nvarchar(10),
@birthday datetime,
@class nvarchar(10),
@pwd nvarchar(10),
@i int,
@r nvarchar(10) output --一个过程可以有多个输出参数但只有一个返回值 输出参数是任何类型
as
if @i = 0
begin
if not exists (select sid from student where sid=@sid)
begin
insert into student values(@sid,@sname,@sex,@birthday,@class,@pwd)
set @r= '添加成功'
end
else
set @r= '重复添加'
end
else
begin
update student set sname = @sname,sex=@sex,birthday=@birthday,class=@class,pwd=@pwd where sid=@sid
if @@rowcount >0
set @r = '修改成功'
else
set @r = '修改无效'
end

declare @r int
exec @r = sp_add 1011,'李四','男' ,'1990-1-12','一班','123'
print @r
------------------------------------查找所有学生分数--------------------一个-------------------------------------------------------------------
alter proc sp_selectAllStudentScore
as
select student.sid,student.sname,ame,score.score
from score right join student
on student.sid=score.sid
left join course
on score.cid=course.cid
------------------------------------------------
exec sp_selectAllStudentScore

select * from student
delete from student where sid= 0
-----------------------------------条件查询学生分数----------------------一个-----------------------------------------------------------
create proc sp_selectstudentscore
@sid int,
@sname nvarchar(10)
as
if @sid>0
begin
select student.sid,student.sname,ame,score.score
from score inner join student
on student.sid=score.sid
inner join course
on score.cid=course.cid
where student.sid=@sid
end
else
begin
select student.sid,student.sname,ame,score.score
from score inner join student
on student.sid=score.sid
inner join course
on score.cid=course.cid
where student.sname like '%'+@sname+'%'
end
---------------------------------------------
exec sp_selectstudentscore 1001,''
exec sp_selectstudentscore '','三'
--------------------------查找与删除学生----------------------------------一个-----------------------------------------------------------
alter proc sp_operstudent
@sid int,
@i int
as
if @
i = 0
select * from student where sid = @sid
else
delete from student where sid = @sid

----------------------登录---------------------------

sql完整数据库操作、存储过程、登录判断,增删改(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
×
二维码
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)