So a database,
will usually have several tables in it.
Here's how we might start for
our image voting app.
The first table represents pictures
that people have uploaded of animals.
The second represents people's votes.
Fluffy, Monster, and
George are all animals,
whose pictures someone has uploaded.
Because, we might have two
animals with the same name.
We give each one a numeric id here.
The pictures tables says
that Fluffy has id 1.
Monster has id 2.
George has id 3.
And so on.
The votes table says, which images
have been displayed together for
voting, and
which one the user picked as the cutest.
Here, the app displayed monster,
ID 2, and George, ID 3,
and the user voted for George.
2 and 3 were matched up,
and 3 was the winner.
Note that in the votes table,
the columns are called left,
right, and winner.
But they match up, to the column
called id in the pictures table.
You can read every row as a sentence.
In the pictures table, the sentences
say Fluffy has id number 1, and
the filename fluffsocute.jpg,
Monster has id number 2,
and filename monstie-basket.png and
so forth.
In the votes table,
the sentences are picture 2 and
picture 3, were displayed and
the user voted for picture 3.
Picture 1 and
picture 3 were displayed, and
the user voted for picture 1 and so on.
So this 3 and this 3, refer to the same
thing, a cute critter with id number 3.
But they're in different tables, and
the columns have different names,
because they play different
roles in different sentences.
Over here we're saying,
which picture has which id?
And over here we're saying, which ones
have been displayed together, and
who got the vote?
So this is the kind of sentence that
this table actually represents.
If you wanted to come up with sentences
like Monster was shown to Fluffy, and
Fluffy got the vote instead
of 2 was shown with 1,
and 1 got the vote for this row here.
We would have to connect rows from
this table, with rows from that table.
That's something we can do
with a database query as well.
Queries that do this are called joins,
and
we'll be seeing a lot of
them later on in the course.
For now, just remember that
a value with the same meaning,
can occur in different tables and
have different column names, and
that we can derive new tables by
linking up existing tables using joins.
عادةً ما تحتوي قاعدة البيانات
.على عدة جداول
فيما يلي طريقة توضح كيف يمكننا
.بدء تشغيل تطبيق التصويت على الصور
يمثل الجدول الأول صورًا
.لحيوانات قام بعض الأشخاص بتحميلها
.بينما يمثل الجدول الثاني أصوات الناس
Fluffy وMonster
وGeorge عبارة عن حيوانات
.تم تحميل صورها بواسطة شخص ما
ونظرًا لاحتمالية وجود
،حيوانين بالاسم ذاته
.خصّصنا لكل حيوان معرفًا رقميًا هنا
،وفقًا لجدول الصور
،فإن معرّف Fluffy هو 1
،ومعرّف Monster هو 2
،بينما معرّف George هو 3
.وهكذا
يشير جدول الأصوات إلى الصور
،التي تم عرضها معًا للتصويت
والصورة التي
.اختارها المستخدم كألطف صورة من وجهة نظره
هنا، عرض التطبيق Monster
،صاحب المعرّف رقم 2، وGeorge صاحب المعرّف رقم 3
.وأدلى المستخدم بصوته لصالح George
،وتمت المقارنة بين عدد أصوات 2 و3
.وفاز رقم 3 في النهاية
لاحظ أن أسماء
،(الأعمدة في جدول الأصوات هي "أيسر" (left
.(و"أيمن" (right)، و"الفائز" (winner
(ويقابل محتويات هذه الأعمدة العمود "المعرّف" (id
.في جدول الصور
.يمكنك قراءة كل صف كجملة
في جدول الصور، تشير الجمل
إلى أن معرّف Fluffy هو 1، واسم ملف صورته
هو fluffsocute.jpg، ومعرّف
،Monsterهو 2
،واسم ملف صورته هو monstie-basket.png
.وهكذا
،وفي جدول الأصوات
،تشير الجمل إلى أنه قد تم عرض الصورتين 2 و3
وأن المستخدم أدلى بصوته
.لصالح الصورة رقم 3
،وتم عرض الصورتين رقم 1 و3
وأدلى المستخدم
.بصوته لصالح الصورة رقم 1، وهكذا
وهذا يعني أن الرقم 3 هنا وهناك يشير إلى نفس
.الشيء، وهو حيوان لطيف رقم معرّفه هو 3
،ولكن هذه المعلومات معروضة في جداول مختلفة
،والأعمدة لها أسماء مختلفة
لأنها تلعب أدوارًا مختلفة
.في جملٍ مختلفة
نوضح هنا
.الصور ومعرّفاتها
،وهنا نشير إلى الصور التي تم عرضها معًا
والصورة الحائزة على أكبر عدد من
.الأصوات
وهذا يعني أن هذه هي الجملة التي يمثّلها
.هذا الجدول بالفعل
إذا أردت كتابة جمل مثل
تم عرض صورة Monster مع صورة Fluffy وحصلت صورة
Fluffy على أكبر عدد من الأصوات بدلاً من
تم عرض صورة 2 مع صورة 1، وحصلت صورة 1
،على أكبر عدد من الأصوات في هذا الصف هنا
يجب أن نربط بين الصفوف الموجودة في هذا الجدول
.وتلك الموجودة في ذلك الجدول
وهذه عملية يمكننا القيام بها
.من خلال تنفيذ استعلام قاعدة البيانات أيضًا
،تُعرف الاستعلامات المخصصة لهذا الغرض باسم استعلامات الدمج
وسنرى استعلامات كثيرة
من هذا النوع لاحقًا
.في الدورة التدريبية
أما الآن، تذكّر فقط أنه من الممكن أن تظهر
،قيمة لها نفس المعنى في جداول مختلفة
بأسماء أعمدة مختلفة، وأنه يمكننا اشتقاق
جداول جديدة من خلال الربط
بين الجداول الموجودة
.باستخدام استعلامات الدمج
Um banco de dados
geralmente usará várias tabelas nele.
Eis aqui como podemos iniciar
nosso aplicativo de votação de imagens.
A primeira tabela representa imagens
que as pessoas carregaram de animais.
A segunda representa os votos das pessoas.
Fluffy, Monster e
George são animais
cujas imagens alguém carregou.
Como podemos ter dois
animais com o mesmo nome,
damos uma id numérica a cada um deles aqui.
A tabela de imagens diz
que Fluffy tem a id 1.
Monster tem a id 2.
George tem a id 3.
E assim por diante.
A tabela de votos informa quais imagens
foram exibidas juntas para
votação, e
qual o usuário achou a mais linda.
Aqui, o aplicativo mostrou Monster,
ID 2, e George, ID 3,
e o usuário votou em George.
2 e 3 foram comparados
e 3 foi o vencedor.
Observe que na tabela de votos,
as colunas se chamam esquerda,
direita e vencedor.
Elas são comparadas à coluna
chamada id na tabela de imagens.
Você pode ler cada linha como uma sentença.
Na tabela de imagens, as sentenças
dizem que Fluffy tem o número de ID igual a 1, e
o nome de arquivo fluffsocute.jpg,
Monster tem o número de ID igual a 2,
e nome de arquivo monstie-basket.png e
assim por diante.
Na tabela de votos,
as sentenças são imagem 2 e
imagem 3 foram exibidas e
o usuário votou na imagem 3.
A imagem 1 e
a imagem 3 foram exibidas e
o usuário votou na imagem 1 e assim por diante.
Então este 3 e este 3 se referem à mesma
coisa, uma criatura fofa com o número de ID igual a 3.
Mas eles estão em tabelas diferentes, e
as colunas têm nomes diferentes,
pois elas desempenham papéis diferentes
em sentenças distintas.
Aqui estamos dizendo,
qual imagem tem que id?
E aqui estamos dizendo, quais
foram exibidos juntos e
quem recebeu o voto?
Este é o tipo de sentença que
esta tabela realmente representa.
Se você quisesse usar sentenças
como Monster foi mostrado com Fluffy e
Fluffy recebeu o voto em vez de
2 foi mostrado com 1
e 1 recebeu o voto para esta linha aqui,
teríamos que conectar as linhas
desta tabela com as linhas dessa tabela.
Isso é algo que também podemos fazer
com uma consulta de banco de dados.
As consultas que fazem isso são chamadas de joins,
e
veremos muitas
delas mais adiante no curso.
Por enquanto, lembre-se apenas que
um valor com o mesmo significado
pode ocorrer em tabelas diferentes e
ter nomes de coluna diferentes, e
que podemos derivar novas tabelas,
vinculando as tabelas existentes usando joins.
一个数据库通常包含几个表
我们或许可以这样开始设计图片投票应用
第一个表代表人们已经上传的动物图片
第二个代表人们的投票
Fluffy、Monster 和
George 都是动物某人上传了它们的图片
因为我们或许会遇到两个动物名字一样的情况
所以在这里 我们给每个动物一个数字 ID
图片表中指定了 Fluffy 的 ID 是 1
Monster 的 ID 是 2
George 的 ID 是 3
依此类推
投票表指定了投票时哪些图片一起显示
哪些图片是用户选出的它们认为最可爱的
这里 应用程序显示 monster 的 ID 是 2 George 的 ID 是 3
用户投票给 George
2和3配对显示 3胜出
注意 在投票表格中
列被命名为 left Right 和 winner
但它们与图片表格中被命名为 ID 的列匹配
你可以将每行作为一个句子
在图片表格中 这些句子说的是 Fluffy 的 ID 号为 1
文件名为 fluffsocute.jpg Monster 的 ID 号为 2
文件名为 monstie-basket.png 诸如此类
在投票表格中 这些句子表示 图片2
和图片3一起显示 用户投票给图片3
图片1和图片3一起显示
用户投票给图片1 等等
因此 这个3和这个3指的是同一样东西 一个 ID 号为3的可爱动物
但它们在不同的表格 而且列的名称不同
因为它们在不同的句子中发挥不同的作用
这里 我们要表达的是 哪个图片对应哪个 ID?
这里 我们要表达的是 哪几张图片一起显示
谁得到了选票?
因此 这是这个表实际上表达的意思
如果对于这一行 你想说的是 Monster 和 Fluffy 一起显示
Fluffy 得到选票 而不是2与1一起显示
1得到选票
我们就需要把这个表格的行与那个表格的行连接在一起
这也是我们能用数据库查询进行的一项操作
执行这一操作的查询语句是 join
我们在后面的课程中会看到很多它的例子
眼下 只要记住含义相同的一个值
可以出现在不同表格中 有不同的列名
我们可以通过使用 join 把现有表连接在一起 得到新的表