官术网_书友最值得收藏!

Chapter 2. Simple Querying

Record retrieval is without doubt the most common activity employed with regard to MySQL and other relational databases. Like most computer programs, MySQL functions on the basis of being invoked with parameters and returning results in accordance with them. As we seen, Python acts as an intermediary to that process. We can use it to access MySQL, login, and connect to a database of our choice.

In this chapter, we will look at the following:

  • Forming a MySQL query directly
  • Passing a query to MySQL
  • User-defined variables in a MySQL query
  • Determining characteristics of a database and its tables
  • Changing queries dynamically, without user input

Working through each of these points will help you at the end of the chapter, when we get to the project: a command-line search tool.

A brief introduction to CRUD

The four basic functions of any persistent storage system like MySQL spell CRUD:

  • Create
  • Read
  • Update
  • Delete

These are key concepts, which each of the basic MySQL commands reflect.

There is nothing technical about the words themselves, but the concepts are very important. They represent the four activities that you can expect to be able to do in every relational database system you use. There are several alternatives to this acronym and keyword series (for example, SCUD for "select, create, update, and delete" or SIDU for "select, insert, delete, and update"). The point of each of these is that database functionality boils down to two sets of opposing activities:

  • Creating and deleting database objects (for example, databases, tables, records)
  • Inserting and reading data (that is writing and reading)

Each of these will be addressed in the coming chapters. In this one, we start with reading data using SELECT.

主站蜘蛛池模板: 修水县| 揭阳市| 孟连| 天门市| 松江区| 洪泽县| 应用必备| 北京市| 兴业县| 文水县| 高邑县| 万山特区| 大英县| 五河县| 酉阳| 射洪县| 阿巴嘎旗| 文山县| 金坛市| 公主岭市| 囊谦县| 夏津县| 青铜峡市| 汉沽区| 仁化县| 丰宁| 建平县| 泰宁县| 新乡市| 云安县| 安仁县| 开阳县| 曲水县| 拉萨市| 辽阳市| 黑龙江省| 牙克石市| 托克逊县| 麟游县| 洱源县| 长葛市|