设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1613|回复: 0
打印 上一主题 下一主题

一个实现递增的存储过程例子

[复制链接]

点击这里给我发消息

跳转到指定楼层
1#
发表于 2003-2-9 17:07:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
use [改为你的SQL数据库名]
IF EXISTS(select OBJECT_ID('p_ins_alm_msg'))
DROP PROCEDURE p_ins_alm_msg
go

create proc p_ins_alm_msg
    @msg_count     int ='2'/*借用一个参数,随便赋予一个默认文本值*/
as
    select @msg_count = value from common_info where name = 'msg_count'/*首先选出新增记录应填写值*/
    update common_info set value = @msg_count+ 1 where name = 'msg_count' and value = @msg_count
                                  /*在本条记录上让新增记录应填写值加1,用于将来(更下一条记录)*/
        if @@rowcount = 0/*如果更新不成功,则返回失败(-1000)*/
            return -1000
    insert into common_info (name)/*插入新记录的值,用参数替代*/
    values(@msg_count)
    return 0
GO
exec p_ins_alm_msg


/*以下是创建本存储过程必须的表的脚本
create table common_info(
name varchar(10),
value int)
insert into common_info values('msg_count', 100)*/
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-6-19 11:35 , Processed in 0.105594 second(s), 24 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表