zoukankan      html  css  js  c++  java
  • 存储过程初探(原创)

     
    存储过程其是就是放在服务器上预先编译好的SQL语句。
     存储过程分两类:系统存储过程(以SP_开头);用户自定义存储过程
    一般来说使用存储过程有以下优点:
     一、减少网络数据传递流量提高T
    -SQL语句执行速度
      用户在使用到SQL语句的时候,如用户进行数据查询,数据插入的时候首先要把相关的SQL语句发送的SQLSERVER,在进行比较复杂的查询等操作时候就要频繁向服务器发送这样的SQL语句,浪费网络带宽,效率低下而且加重服务器的负担。而存储过程经过编译存放在服务上,使用存储过程要比单条SQL语句快的多。
     
    二、适合模块化编程,提高系统的通用性
     存储过程在被创建以后,可以在程序中被多次调用而不用重复编写SQL语句。
     
    三、可以更有效的管理用户操作数据库的权限
     通过SQLSERVER分配权限更安全
     
    存储过程的创建和使用
    创建存储过程的基本语法:
    Create Procedure pro_name
    @param1 type1,
    @param2 type2
    AS
    SQL语句
     
    创建一个没有参数的查询语句
    Create pro user
    as
    select user,pass from users
     
    创建一个带输入参数的语句
    Craate pro 
    user
    @user NVarchar(50)
    AS
    select user,pass from users where user=@user
     
    创建一个带出入,输出参数
    Create pro user
    @user NVarchar(50),
    @count_user int OUTPUT
    AS
    select user,pass from users where user=@user
    select @user_count=count(userfrom users where user=@user
     
    存储过程的调用:
    //输入参数并付值
    mycommand.commandType
    =CommandType.StoredProcedure;
    mycommand.Parameter.
    Add("@user",SqlDbType.NVarchar,50);
    mycommand.Parameter.
    =输入的值;
    mycommand.Parameter.Direction
    =ParameterDirection.Input; 
    //输出参数并付值
    mycommand.commandType
    =CommandType.StroedProcedure;
    mycommand.
    Add("@user,SqlDbType.int);
    mycommand.Parameter.Direction
    =ParameterDirection.Output;
  • 相关阅读:
    js 右击
    javascript 中的函数,控制流, 事件委托
    javascript 的 this , js 线程
    javascript 中的var : 隐含变量 全局变量 变量提升
    明日
    ajax循环json 中的 for(var prop in data) 与 hasProperty()
    js继承机制
    callee, caller,toString(),String()
    解决eclipse中jsp下无代码提示问题
    商业模式
  • 原文地址:https://www.cnblogs.com/wdx2008/p/776705.html
Copyright © 2011-2022 走看看