zoukankan      html  css  js  c++  java
  • 增删改查存储过程

    select * from UserInfo
    
    ---------------------------------添加存储过程------------------------------
    if OBJECT_ID('P_add') is not null
    drop proc P_add
    go
    create proc P_add
    --参数
    @UserName varchar(100),
    @UserPwd varchar(100),
    @UserSex int,
    @UserDate datetime,
    @msg varchar(max) out
    as
    --变量
    declare @bcount int,@acount int
    --赋值
    set @bcount=(select COUNT(1) from UserInfo)--添加之前条数
    insert into UserInfo values(@UserName,@UserPwd,@UserSex,@UserDate)
    set @acount=(select COUNT(1) from UserInfo)--添加之后的条数
    if    @acount>@bcount
    set @msg='添加成功'
    
    -----------------------------------删除存储过程------------------------------
    if OBJECT_ID('P_Delete') is not null
    drop proc P_Delete
    go
    create proc P_Delete
    @id int
    as
    delete from UserInfo where id in (@id)
    -----------------------------------修改存储过程------------------------------
    if OBJECT_ID('P_Update') is not null
    drop proc P_Update
    go
    create proc P_Update
    --参数
    @UserName varchar(100),
    @UserPwd varchar(100),
    @UserSex int,
    @UserDate datetime,
    @Id int,
    @msg varchar(max) out
    as
    update UserInfo set 
    UserName=@UserName,
    UserPwd=@UserPwd,
    UserSex=@UserSex,
    UserDate=@UserDate
    where Id=@Id
    set @msg='修改成功'
    ------------------------------------批删除存储过程-------------------------------------
    if OBJECT_ID('P_dels') is not null
    drop proc P_dels
    go
    
    create proc P_dels 
    @id varchar(max)--定义变量要删除数据的id    1 ,2 , 3
    as 
    declare @temp table (id int)--临时表
    declare @index int --下标
    
    set @index=CHARINDEX(',',@id)--查找逗号下标
    print @index
    while @index>1  --判断逗号下标
    begin
    
    insert into @temp values(LEFT(@id,@index-1))--LEFT(要截取的字符串,截取个数) 字符串下标从1开始
    set @id=SUBSTRING(@id,@index+1,LEN(@id)-@index)
    set @index=CHARINDEX(',',@id)--查找逗号下标
    
    end
    if @id<>'' --最后一个
    insert into @temp values(@id)
    
    delete from UserInfo WHERE ID in(select id from @temp)
    
    
    ----------------------------------查询分页------------------------------
    if OBJECT_ID('P_Show') is not null
    drop proc P_Show
    GO
    CREATE proc P_Show
    @pageIndex int,
    @pageSize int,
    @UserName varchar(50)=null,
    @totalCount int out
    as
    
    declare @sql varchar(max),--sql语句
            @sqlWhere varchar(max),--查询条件
            @rid int --序列号
    
    ---初始化变量
    set @sql=''
    set @sqlWhere=''
    set @rid=(@pageIndex-1)*@pageSize
    set @totalCount=(select COUNT(1) from UserInfo)
    
    if @UserName is not null
       begin 
       set @sqlWhere=' and UserName like ''%'+@UserName+'%'''
       set @totalCount=(select COUNT(1) from UserInfo where UserName like '%'+@UserName+'%')
    end
    
    set @sql='select top '+STR(@pageSize)+' * from 
    (
     select *,ROW_NUMBER() over(order by UserDate) as rid from UserInfo where 1=1 '+@sqlWhere+'
    ) temp
    where rid>'+STR(@rid)
    exec (@sql)
    
       

    2020-01-07

  • 相关阅读:
    用 PHP 和 MySQL 保存和输出图片
    windows XP+Apache+PHP5+MySQL的安装与配置方法
    PHP语法学习笔记
    wap开发环境搭建
    三款免费的PHP加速器:APC、eAccelerator、XCache比较
    window下apache与tomcat整合
    用PHP的ob_start();控制您的浏览器cache!
    一些经典常用的正则表达式
    windows下为apache配置多个站点
    windows下IIS与Tomcat共存的问题
  • 原文地址:https://www.cnblogs.com/2018cjx/p/12159650.html
Copyright © 2011-2022 走看看