黑马程序员技术交流社区
标题: 关于存储过程的基本使用 [打印本页]
作者: 中山郎 时间: 2012-10-9 14:31
标题: 关于存储过程的基本使用
存储过程的概念:
存储过程是一种数据库对象,为了实现某个特定的任务,将一组预编译的SQL语句将以一个存储单元的形式存储在服务器上,供用户调用,存储过程在第一次执行时进行编译,然后将编译好的代码保存在高速缓存中,以便以后调用,这样可以提高代码的执行效率。
--创建一个简单的存储过程
create proc UserId @name varchar(30)
as
select LoginId from UserInfo where LoginPWD=@name
---执行存储过程
execute UserId
---查看存储过程的一般信息
exec sp_help UserId
---查看存储过程的定义信息
exec sp_helptext UserId
---查看存储过程的相关性
exec sp_depends UserId
---创建带有返回参数的存储过程
create proc score @name float output
as
select @name=AVG(StudentResult) from Result
----执行返回参数的操作
declare @pj float
exec score @pj output
print '所有学生的平均成绩是:'+STR(@pj)
---创建多个参数的存储过程
create proc score @studentno varchar(30) ,@grade float output
as
select @grade=StudentResult from Result where StudentNo=@studentno
declare @chengji float
exec score '001',@chengji output
print'此学生的成绩是:'+STR(@chengji)
存储过程的优点:
执行速度更快;允许模块化程序设计;提高系统安全性;减少网络流通量。
作者: 许庭洲 时间: 2012-10-9 15:45
值得学习ing!
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) |
黑马程序员IT技术论坛 X3.2 |