zoukankan      html  css  js  c++  java
  • 2月27日 常用存储过程

    1.分页:

    ---存储过程、row_number完成分页
    if (object_id('pro_page', 'P') is not null)
        drop proc proc_cursor
    go
    create proc pro_page
        @startIndex int,
        @endIndex int
    as
        select count(*) from product
    ;    
        select * from (
            select row_number() over(order by pid) as rowId, * from product 
        ) temp
        where temp.rowId between @startIndex and @endIndex
    go
    --drop proc pro_page
    exec pro_page 1, 4
    --
    --分页存储过程
    if (object_id('pro_page', 'P') is not null)
        drop proc pro_stu
    go
    create procedure pro_stu(
        @pageIndex int,
        @pageSize int
    )
    as
        declare @startRow int, @endRow int
        set @startRow = (@pageIndex - 1) * @pageSize +1
        set @endRow = @startRow + @pageSize -1
        select * from (
            select *, row_number() over (order by id asc) as number from student 
        ) t
        where t.number between @startRow and @endRow;
    
    exec pro_stu 2, 2;

    2.删除表

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go
    
    
    --        <><><><><><><><><><><><><>
    --        <>                      <>
    --        <>      类_删除表       <>
    --        <>                      <>
    --        <><><><><><><><><><><><><>
    
    
    Create PROCEDURE [dbo].[类_删除表]
    
    
         @Sql_Table varchar(30) = 'temp_1'    -- 要删除的数据表名
    As
    BEGIN
    	SET NOCOUNT ON;
     
        declare @Sql_Sql nvarchar(200)
        declare @uuu int
        set @uuu=0
    
    
    	set @Sql_Sql='select @uuu=count(id) from sysobjects where id = object_id(N'+''''+'[dbo].['+@Sql_Table+']'+''''+') and OBJECTPROPERTY(id, N'+''''+'IsUserTable'+''''+') = 1'
        
        EXEC sp_executesql @Sql_Sql,N'@uuu int output',@uuu OUTPUT
    
    
        if @uuu>0
    	exec('drop table '+@Sql_Table)
    
    
    END
    

      

  • 相关阅读:
    jQuery选择器
    js创建对象的几种方式
    call()和apply()
    js实现二分查找
    关于HTTP请求
    node/npm命令收集
    微信H5开发笔记——记录开发中用到的知识(手机摇动、事件捕获、wechat禁止分享、正则、promise...)
    css额外学习笔记
    gulp 结构和运行步骤——笔记1
    手机版H5开发--收集大神们的笔记
  • 原文地址:https://www.cnblogs.com/tzq9308/p/4303685.html
Copyright © 2011-2022 走看看