1、系统存储过程,以sp/xp开头
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'xp_cmdshell',1
reconfigure
go
exec xp_cmdshell 'md e:\demo'
2、自定义存储过程
if exists(select name from sysobjects where name='proc_Student_Querry' and type='p')
drop proc proc_Student_Querry
go
--查询,不带参数
create proc proc_Student_Querry
as
select * from students
go
--调用
proc_Student_Querry
--带输入参数,向学员表添加数据
drop proc proc_students_insert
create proc proc_students_insert
@stuname varchar(20),
@stusex varchar(2)='男',
@depId int=1,
@stuage int=30
as
begin
insert into students values(@stuname,@stusex,@depId,@stuage)
select * from students
end
go
proc_students_insert '何2家','男',2,32
proc_students_insert '张2继科'
--带输出参数,查询平均年龄和最大年龄的学员编号
/*alter table students add stuAge int
create proc proc_QuerryStudent
@avgage int output,
@stuno int output
as
begin
select @avgage=avg(stuage) from students
select @stuno=stuno from students where stuage=(select max(stuage) from students)
end
go
declare @avgage int,@stuno int
exec proc_QuerryStudent @avgage output,@stuno output
print '平均年龄:'+convert(varchar,@avgage)
print '年龄最大的学号:'+convert(varchar,@stuno)
*/
--带输出参数,查询平均年龄和最大年龄的学员名字
drop proc proc_QuerryStudent
create proc proc_QuerryStudent
@avgage int output,
@studentname varchar(30) output
as
begin
select @avgage=avg(studentage) from students
select @studentname=studentname from students where studentage=(select max(studentage) from students)
end
go
declare @avgage int,@studentname varchar(30)
exec proc_QuerryStudent @avgage output,@studentname output
print '平均年龄:'+convert(varchar,@avgage)
print '年龄最大的名字:'+@studentname
--带返回值的存储过程,读取平均年龄
if exists(select name from sysobjects where name='proc_students_avgage' and type='p')
drop proc proc_students_avgage
go
create proc proc_students_avgage
as
begin
declare @avgage int
select @avgage=avg(studentage) from students
return @avgage
end
go
declare @age int
exec @age=proc_students_avgage
print @age
--或者
declare @age int
exec @age=proc_students_avgage
print '平均年龄为:'+convert(varchar,@age)
--这是个问题?
--自定义错误函数raiserror(‘错误文本’,错误级别1-17,错误状态1-127)
--改写向学院表添加数据的存储过程
--要求年龄为18岁以上,性别为男或女
if exists(select name from sysobjects where name='proc_studens_insert' and type='p')
drop proc proc_studens_insert
go
create proc proc_studens_insert
@stuname varchar(20),
@stusex varchar(10)='男',
@depId int=1,
@stuage int=30
as
begin
if(@stuage<18)
begin
raiserror('年龄必须至少为18岁',16,100)
return
en
SQL_SERVER数据库开发之存储过程应用_理学_高等教育_教育专区 暂无评价0人阅读0次下载举报文档 SQL_SERVER数据库开发之存储过程应用_理学_高等教育_教育专区。...
sql 数据库 第十二章 SQL Server 2008存储过程_IT/计算机_专业资料。SQL Server 数据库程序设计 授课教师: 授课教师:姜姗 存储过程和触发器掌握存储过程的定义...
SqlServer数据库备份存储过程_IT/计算机_专业资料。SqlServer数据库备份存储过程SqlServer 数据库备份存储过程: set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ...
上一页 下一页 返回本章首页 第5章 数据库对象的操作 5.5.1 创建存储过程在SQL Server中,可以使用三种方法创建存储过 程: ①使用创建存储过程向导创建存储...
剖析SQL Server数据库扩... 4页 免费 数据库(sql)视图、存储过... 15页 1下载券 SQL--存储过程实现数据库... 3页 免费 【原创:数据库】SQL SE... ...
SQL Server——如何正确理解存储过程_IT/计算机_专业资料。SQL Server 如何正确理解存储过程存储过程也称为存储查询,是存储在数据库中预先定义的 SQL 语句。它可 ...
SQL Server存储过程及触发器详细讲解_IT/计算机_专业资料。sql server 存储过程详细讲解和触发器的实例,很有帮助,数据库的一个重难点。...
SQL Server 存储过程详解 ◆优点: 执行速度更快。存储过程只在创造时进行编译,...TEXT、 SET SHOWPLAN_XML、USE database_name 其他数据库对象均可在存储过程中...
第8章 存储过程 8.1 存储过程简介 创建存储过程 执行存储过程 修改和删除存储过程 8.2 8.3 8.4 Server数据库系统中 数据库系统中, 在 SQL Server 数据库...
SQL Server 存储过程入门案例详解作者: Jackie, 出处:IT 专家网,责任编辑: 王晓晨, 2008-07-17 12:56 有了存储过程之后,与数据库的交互就没有必要在程序中写...
热门文档