Real SQL Programming

目录

[SQL in Real Programs](#SQL in Real Programs)

Options

[Stored Procedures](#Stored Procedures)

[Advantages of Stored Procedures](#Advantages of Stored Procedures)

[Parameters in PSM](#Parameters in PSM)


SQL in Real Programs

  • We have seen only how SQL is used at the generic query interface --- an environment where we sit at a terminal and ask queries of a database.

  • Reality is almost always different:

conventional programs interacting with SQL.

(我们只是看见了SQL是如何在常规的查询接口中的使用,也就是直接通过终端 对数据库进行交互,但实际上通常是常规程序与SQL语言的交互)

Options

  • Code in a specialized language is stored in the database itself (e.g.PSM, PL/SQL).
  • SQL statements are embedded in a host language(e.g., C).
  • Connection tools are used to allow a conventional language to access a database (e.g., CLI, JDBC, PHP/DB).

(常规程序与SQL语言的交互模式: 数据库储存代码、SQL内嵌、连接工具)

Stored Procedures

  • PSM, or "persistent stored modules, " allows us to store procedures as database schema elements.(持久储存模块允许我们将储存模式作为数据库模式元素)

  • PSM = a mixture of conventional statements (if, while, etc.) and SQL.

  • Lets us do things we cannot do in SQL alone.

数据库中的储存过程和函数的区别在于,函数可以直接通过函数名的引用得到函数值,但是储存过程不行

Advantages of Stored Procedures

  • Share Application Logic(共享应用逻辑)
  • Shield Database Schema Details(屏蔽数据库细节)
  • Provide Security Mechanisms(提供安全机制 )
  • Improve Performance(提升性能)
  • Reduce Network Traffic(减少网络流量)

Parameters in PSM

Unlike the usual name-type pairs in languages like C, PSM uses mode- name-type triples, where the modecan be:

  • IN = procedure uses value, does not change value.(传入参数,只能调用不能修改)

  • OUT = procedure changes, does not use.(传出参数,可以在储存过程被修改)

  • INOUT = both

想得到储存过程的返回值,虽然不能直接通过调用储存过程名字,但是可以调用OUT参数

相关推荐
牛奶咖啡132 小时前
关系数据库MySQL的常用基础命令详解实战
数据库·mysql·本地远程连接到mysql·创建mysql用户和密码·修改mysql用户的密码·设置mysql密码的使用期限·设置和移除mysql用户的权限
ANYOLY2 小时前
Redis 面试宝典
数据库·redis·面试
鲲志说3 小时前
数据洪流时代,如何挑选一款面向未来的时序数据库?IoTDB 的答案
大数据·数据库·apache·时序数据库·iotdb
没有bug.的程序员3 小时前
MVCC(多版本并发控制):InnoDB 高并发的核心技术
java·大数据·数据库·mysql·mvcc
脑花儿4 小时前
ABAP SMW0下载Excel模板并填充&&剪切板方式粘贴
java·前端·数据库
SELSL4 小时前
SQLite3的API调用实战例子
linux·数据库·c++·sqlite3·sqlite实战
洲覆4 小时前
Redis 核心数据类型:从命令、结构到实战应用
服务器·数据库·redis·缓存
傻啦嘿哟4 小时前
Python SQLite模块:轻量级数据库的实战指南
数据库·python·sqlite
维尔切5 小时前
HAProxy 负载均衡器
linux·运维·数据库·负载均衡
什么半岛铁盒5 小时前
C++项目:仿muduo库高并发服务器-------Channel模块实现
linux·服务器·数据库·c++·mysql·ubuntu