了解SQL数据库的工作方式

 MySQL is a relational database often used to store data for websites working in conjunction with PHP. Relational means that different tables of the database can be cross-referenced to one another. SQL stands for "Structured Query Language" which is the standard language used to interact with databases. MySQL was built using the SQL base and released as an open source database system. Because of its popularity, it is highly supported with PHP. Before you start learning to make databases it is important to understand more about what tables are.​​

MySQL是一个关系数据库,通常用于存储与PHP结合使用的网站的数据。 关系意味着数据库的不同表可以相互交叉引用。 SQL代表“结构化查询语言” ,它是用于与数据库进行交互的标准语言。 MySQL是使用SQL库构建的,并作为开源数据库系统发布。 由于其受欢迎程度,PHP高度支持它。 在开始学习制作数据库之前,重要的是要进一步了解什么是表。

什么是SQL表? ( What are SQL tables? )

SQL Table

A database can be made up of many tables, and a table in a database is made up of intersecting columns and rows that form a grid. A good way to think about this is to imagine a checkerboard. Along the top row of the checkerboard, there are labels for the data you wish to store, for example, Name, Age, Gender, Eye Color, etc. In all the rows below, information is stored. Each row is one entry (all the data in a single row, belongs to the same person in this case) and each column contains a specific type of data as indicated by its label. Here is something to help you visualize a table:

数据库可以由许多表组成,数据库中的表由形成网格的相交的列和行组成。 考虑这一点的一种好方法是想象一个棋盘格。 在棋盘格的第一行中,有您要存储的数据的标签,例如,名称,年龄,性别,眼睛颜色等。在下面的所有行中,都存储有信息。 每一行都是一个条目(在同一行中,所有数据都属于同一个人),并且每一列都包含一种特定类型的数据,如其标签所示。 以下是可以帮助您可视化表格的内容:

了解SQL关系数据库 ( Understanding SQL Relational Databases )

So what is a 'relational' database, and how does it use these tables? Well, a relational database lets us 'relate' data from one table to another. Let's say for example we were making a database for a car dealership. We could make one table to hold all of the details for each of the cars we were selling. However, the contact information for 'Ford' would be the same for all of the cars they make, so we do not need to type that data more than once.

那么什么是“关系”数据库,以及它如何使用这些表? 好吧,关系数据库使我们可以将数据从一个表“关联”到另一个表。 举例来说,假设我们正在为一家汽车经销商建立数据库。 我们可以做一张桌子来存放我们所售汽车的所有详细信息。 但是,“福特”的联系信息对于他们生产的所有汽车都是相同的,因此我们无需多次键入该数据。

What we can do is create a second table, called manufacturers. In this table, we could list Ford, Volkswagen, Chrysler, etc. Here you could list the address, phone number, and other contact information for each of these companies. You could then dynamically call the contact information from our second table for every car in our first table. You would only ever have to type this information once despite it being accessible for every car in the database. This not only saves time but also valuable database space as no piece of data needs to be repeated.

我们可以做的是创建另一个表,称为“ 厂商” 。 在此表中,我们可以列出福特,大众,克莱斯勒等。在这里您可以列出每个公司的地址,电话号码和其他联系信息。 然后,您可以从第二个表中为第一个表中的每辆车动态调用联系信息。 尽管数据库中的每个汽车都可以访问该信息,但您只需键入一次即可。 这不仅节省了时间,而且节省了宝贵的数据库空间,因为不需要重复任何数据。

SQL数据类型 ( SQL Data Types )

Each column can only contain one type of data which we must define. An example of what this means is; in our age column we use a number. We could not change Kelly's entry to "twenty-six" if we had defined that column to be a number. The main data types are numbers, date/time, text, and binary. Although these have many subcategories, we will just touch on the most common types that you will use in this tutorial.

每列只能包含我们必须定义的一种数据类型。 这意味着一个例子。 在“年龄”列中,我们使用数字。 如果我们已将该列定义为数字,则无法将Kelly的条目更改为“二十六”。 主要数据类型为数字,日期/时间,文本和二进制。 尽管它们有许多子类别,但我们只涉及您将在本教程中使用的最常见的类型。

INTEGER: This stores whole numbers, both positive and negative. Some examples are 2, 45, -16 and 23989. In our example, the age category could have been an integer.

整数:整数存储正数和负数。 一些示例是2、45,-16和23989。在我们的示例中,年龄类别可以是integer

FLOAT: This stores numbers when you need to use decimals. Some examples would be 2.5, -.664, 43.8882, or 10.00001.

FLOAT:当你需要使用小数此店号。 一些示例是2.5,-。664、43.8882或10.00001。

DATETIME: This stores a date and time in the format YYYY-MM-DD HH:MM:SS

DATETIME:以YYYY-MM-DD HH:MM:SS格式存储日期和时间

VARCHAR: This stores a limited amount of text or single characters. In our example, the name column could have been varcar (short for a variable character)

VARCHAR:这会存储少量文本或单个字符。 在我们的示例中,名称列可能是varcar(可变字符的缩写)

BLOB: This stores binary data other than text, for example, file uploads.

BLOB:它存储文本以外的二进制数据,例如文件上传。

翻译自: https://www.thoughtco.com/understanding-how-sql-databases-work-2693878

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 扫一扫,分享海报

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2022 CSDN 皮肤主题:编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值