SQL数据库语言的使用.doc
《SQL数据库语言的使用.doc》由会员分享,可在线阅读,更多相关《SQL数据库语言的使用.doc(3页珍藏版)》请在冰点文库上搜索。
![SQL数据库语言的使用.doc](https://file1.bingdoc.com/fileroot1/2023-4/30/b7c8835a-3133-46fc-ac23-ca57adbe6c49/b7c8835a-3133-46fc-ac23-ca57adbe6c491.gif)
1.在xk数据库中创建一个名为p_studentt的存储过程,该存储过程要求返回student表中所有班级代码为20000001的记录。
Createprocedurep_student
As
Select*fromstudentwhereclassno=’20000001’
2.在xk数据库中创建一个名为p_studentpara的存储过程,该存储过程能根据给定的班级返回该班级代码对应的student表中的记录。
createprocedurep_studentpara
@classnovarchar(8)
as
select*fromstudentwhereclassno=@classno
execp_studentpara@classno='20000001'
go
execp_studentpara@classno='20000002'
go
3.创建存储过程p_classnum,要求能够根据用户给定的班级代码,统计该班的人数,并将人数以输出变量返回给用户。
@parameter_namedatatype=[default]output
createprocedurep_classnum
@classnovarchar(8),@classnumsmallintoutput
as
set@classnum=(selectcount(*)fromstudent
whereclassno=@classno
)
print@classnum
测试语句:
declare@classnovarchar(8),@classnumsmallint
set@classno='20000001'
execp_classnum@classno,@classnumoutput
4.修改
Alter
修改存储过程p_studentpara,使其能根据用户提供的班级名称,而不是班级代码进行模糊查询,并且要求加密。
alterprocedurep_studentpara
@classnamevarchar(20)
withencryption
as
selectclassname,stuno,stuname,pwd
fromstudent,class
wherestudent.classno=class.classno
andclassnamelike'%'+@classname+'%'
5.系统过程
Execsp_addlogin'student01'
go
execsp_addlogin'student02','02'
go