• 数据库存储过程的写法


      系统数据库:

    exec sp_databases; --查看数据库
    exec sp_tables;        --查看表
    exec sp_columns student;--查看列
    exec sp_helpIndex student;--查看索引
    exec sp_helpConstraint student;--约束
    exec sp_stored_procedures;
    exec sp_helptext 'sp_stored_procedures';--查看存储过程创建、定义语句 经常用到这句话来查看存储过程,like sp_helptext sp_getLoginInfo.
    exec sp_rename student, stuInfo;--修改表、索引、列的名称
    exec sp_renamedb myTempDB, myDB;--更改数据库名称
    exec sp_defaultdb 'master', 'myDB';--更改登录名的默认数据库
    exec sp_helpdb;--数据库帮助,查询数据库信息
    exec sp_helpdb master;

      存储过程基本语法:

    CREATE  PROC[EDURE]  存储过程名
    
                  @参数1  数据类型 = 默认值,
    
                   …… ,
    
                  @参数n  数据类型 OUTPUT
    
                AS
    
                SQL语句
    
        GO

      实例:(制作考试分数条)

    create proc sp_scorerank
        @Gid varchar(10),
        @Cid varchar(10)
        as
            begin
                if(@Cid='')
                    begin
                        select a.StuName,Chinese+English+math Total,b.Chinese,b.English,b.Math,
                        Rank() over(order by Chinese+English+math desc) 
                        from Students a left join Score b on a.StuID=b.SID
                        where a.GradeID=@Gid 
                    end
                else
                    begin
                        select a.StuName,Chinese+English+math Total,b.Chinese,b.English,b.Math,
                        Rank() over(order by Chinese+English+math desc) 
                        from Students a left join Score b on a.StuID=b.SID
                        where a.GradeID=@Gid and a.ClassID=@Cid 
                    end
            end
        go
    
        exec sp_scorerank 'G02',''

      查询结果:

    记录编程的点滴,体会学习的乐趣
  • 相关阅读:
    爽肤水
    Python面向对象关系
    Linux多线程编程
    Python数据库工具类MySQLdb使用
    Python配置工具类ConfigParser使用
    采用RedisLive监控Redis服务——安装手册
    采用JavaMelody监控Tomcat服务——安装手册
    怎么做性能测试--响应时间
    robot framework测试驱动无法定位页面元素
    使用Loadrunner对IBM MQ进行性能测试
  • 原文地址:https://www.cnblogs.com/AduBlog/p/13474757.html
Copyright © 2020-2023  润新知