注册 登录
编程论坛 SQL Server论坛

请教这一存储过程???

tel1982 发布于 2007-10-11 17:58, 644 次点击

请问这一段存储过程意思是什么?希望高手给与指点。
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE procedure [dbo].[DeleteCameraType]
@CT_ID bigint,
@Reint int output
as
begin
--系统数据不能删除 07-08-04
if @CT_ID<=3
begin
set @Reint=-3
return
end
declare @CountSon int
set @Reint=-1
select @CountSon=Count(*) from Camera where CT_ID=@CT_ID
--有镜头不能删除
if @CountSon>0
begin
set @Reint=-2
return
end

delete from CameraType where CT_ID=@CT_ID and CT_ID > 3
set @Reint=0
end


GO

9 回复
#2
purana2007-10-11 19:15
不是有注释吗?
#3
tel19822007-10-12 16:08
我知道,我想请你们帮我从头到尾详细解释一下。
#4
purana2007-10-12 16:10
这个存储过程比较简单..
好像没什么要讲的吧.
#5
tel19822007-10-12 17:30
那麻烦你帮我解释这一段
declare @CountSon int
set @Reint=-1
select @CountSon=Count(*) from Camera where CT_ID=@CT_ID
代码吧
谢谢了~~!
#6
purana2007-10-12 17:33
declare @CountSon int --声明变量
set @Reint=-1 --设置@Reint为-1
select @CountSon=Count(*) from Camera where CT_ID=@CT_ID --将CT_ID列为@CT_ID的行总数赋值给@CountSon.
#7
tel19822007-10-12 18:00
那么设置@Reint为-1的作用是干嘛用的呀?
#8
tel19822007-10-12 18:00
我在写存储过程方面很菜的,请多多指教啊~~!
#9
purana2007-10-12 18:17

从这个存储过程来看.
因为@Reint 是输出参数.
而过程中.根据不同的条件.进行不同的赋值.
这样就可以根据输出的值来判断是是执行成功.还是出什么错了.
比如你这里.
如果@Reint 返回-3则是系统不能删除的数据...

#10
tel19822007-10-12 18:24

很感谢你!

1