马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?站点注册 
 
 
 
×
 
昨晚有空,把 sybase 系统过程 sp_who , DDL 后分析了一下,全文如下:  
  
  
 -- 以下是 DDL 出来的内容:  
 -----------------------------------------------------------------------------  
 -- DDL for Stored procedure 'sybsystemprocs.dbo.sp_who'  
 -----------------------------------------------------------------------------  
 -- 以上是注释  
  
 print 'Creating Stored procedure sp_who'  
 go   
 -- 上面两句是显示一句话, go 是执行(下同)  
  
 use sybsystemprocs   
 go   
 -- 选择将要使用的数据库(存储过程建在什么数据库里)  
  
 setuser 'dbo'   
 go   
 -- 使当前用户充当 'dbo  
  
 -- 以下是存储过程的实体  
 /* Sccsid = "%Z% generic/sproc/%M% %I% %G%" */  
 /*  4.8  1.1  06/14/90  sproc/src/serveroption */  
  
 /*  
 ** Messages for "sp_who"   17nnn  
 **   
 ** 17231, "No login with the specified name exists."   
 */  
 -- 以上是注释  
  
 create procedure sp_who @loginame varchar(30) = NULL as  
 -- 创建存储过程 sp_who) 的参数 loginame  
  
 declare @low int  
 declare @high int  
 declare @spidlow int  
 declare @spidhigh int  
 declare @len1 int, @len2 int, @len3 int  
 -- 申明了若干变量  
  
 if @@trancount = 0  
 --@@ 开头的都是系统全局变量  
 --@@trancount 是用来检查事务嵌套级别的全局变量,批处理中每个 begin transaction 将事务计数加 1  
 begin  
   set chained off  
 -- 用在会话开始和事务结束时使用,指示是否在第一个数据检索或数据修改语句前开始一个事务(是否在 delte 、 fetch 、 insert 、 open 、 select 、 update 前隐式执行一个 begin transaction 命令)  
 end  
  
 set transaction isolation level 1  
 -- 设置会话所用的事务隔离级别。当设置此选项后,所有当前或将来的事务都将在些隔离级别上运行  
 --level 1  的意义:允许对数据使用共享读取锁  
 select @low = @@minsuid, @high = @@maxsuid,   
        @spidlow = @@minspid, @spidhigh = @@maxspid  
 -- 给局部变量赋值,四个全局变量的含义:  
 --@@minsuid :最小服务器用户 ID  
 --@@maxsuid :最大服务器用户 ID  
 --@@minspid :最小服务器进程 ID  
 --@@maxspid :最大服务器进程 ID  
  
 if @loginame is not NULL  
 -- 判断存储过程的参数是否为空  
 begin  
 -- 开始一个新的批  
   select @low = suser_id(@loginame), @high = suser_id(@loginame)  
   --suser_id: 系统函数,返回服务器用户在 syslogins 表中的 ID 号  
  
   if @low is NULL  
   -- 如果参数 @loginame 不正确的话, suser_id 应该返回 NULL  
   begin  
    if @loginame like "[0-9]%"  
    -- 判断一下 @loginame 是不是数字开头的字符串  
    begin  
    -- 如果是的话把说明参数 @loginame 应该是服务器系统进和 ID  
     select @spidlow = convert(int, @loginame),  
          @spidhigh = convert(int, @loginame),  
          @low = 0, @high = @@maxsuid  
    -- 把参数 @loginame 转换成 int 型并赋给 @spidlow 和 @spidhigh  
    end  
    else  
    -- 如果不是数据开头的字符串,返回错误代码,并返回  
    begin  
     /*  
     ** 17231, "No login with the specified name exists."   
     */  
     raiserror 17231  
     -- 返回的错误号是 17231  
     --raiserror 的作用是返回预定义的错误号  
     return (1)  
    end  
   end  
 end  
 -- 以上进行的工作是将 @loginame 进行处理,生成下面查询语言的所需的条件值 @low 、 @high 、 @spidlow 、 @spidhigh 
   |