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
    

      

  • 相关阅读:
    spring 04-Spring框架依赖注入基本使用
    spring 03-Spring开发框架之控制反转
    spring 02-Maven搭建Spring开发环境
    spring 01-Spring开发框架简介
    JVM堆内存、方法区和栈内存的关系
    jvm 07-java引用类型
    jvm 06-G1收集器
    jvm 05-JVM垃圾收集策略
    jvm 04-JVM堆内存划分
    CSS书写顺序
  • 原文地址:https://www.cnblogs.com/tzq9308/p/4303685.html
Copyright © 2011-2022 走看看