zoukankan      html  css  js  c++  java
  • mysql 存储过程

    存储过程:

      优势:1.较快执行速度(比单个的SQL语句快)

                 2.调用时只需存储过程名和参数

      分类:1.系统存储过程:

            1.系统创建,有一些存储过程会在创建新的数据库时自动创建;

            2.名字以“sp_”开头

         2.自定义存储过程:

    create proc | procedure pro_name
        [{@参数数据类型} [=默认值] [output],
         {@参数数据类型} [=默认值] [output],
         ....
        ]
    as
        SQL_statements
    

      具体用法示例:

      1.创建不带参数存储过程:

    --创建存储过程
    if (exists (select * from sys.objects where name = 'proc_get_student'))
        drop proc proc_get_student
    go
    create proc proc_get_student
    as
        select * from student;
    
    --调用、执行存储过程
    exec proc_get_student;
    

      2.创建带参存储过程:

    --带参存储过程
    if (object_id('proc_find_stu', 'P') is not null)
        drop proc proc_find_stu
    go
    create proc proc_find_stu(@startId int, @endId int)
    as
        select * from student where id between @startId and @endId
    go
    
    exec proc_find_stu 2, 4;
    

      3.修改存储过程:

    --修改存储过程
    alter proc proc_get_student
    as
    select * from student;
    

      

  • 相关阅读:
    xml文档格式学习笔记
    Visual Studio学习记录
    Java学习笔记
    C#项目学习记录
    Linux命令行与shell脚本编程大全 学习笔记
    NodeJS (npm) 学习笔记
    Angular学习笔记
    TypeScript学习笔记
    java 项目相关 学习记录
    docker学习记录
  • 原文地址:https://www.cnblogs.com/gaara-zhang/p/9955694.html
Copyright © 2011-2022 走看看