跳到主要内容

数据库

主题讲义 (PDF)

国际文凭组织 · IB Diploma · 计算机科学 · HL 知识点 3 3:47 英语旁白 · 英中内嵌字幕

空格播放 · ←/→ 快退/进5秒 · j/l 快退/进10秒 · f 全屏 · ,/. 倍速

章节

文本转录
Duplicating a user address in every order can produce conflicting records when the address changes. 在每条订单中重复存储用户地址,当地址发生变化时,可能会产生冲突的记录。
A relational table contains rows and attributes. 关系表包含行和属性。
A primary key identifies a row; a foreign key links to a referenced key in another table. 主键用于标识一行;外键链接到另一张表中的引用键。
Normalization can reduce avoidable duplication and update anomalies while preserving meaningful relationships. 规范化可以减少可避免的重复和更新异常,同时保留有意义的关系。
Primary key is an attribute set that uniquely identifies a table row. 主键是唯一标识表行的属性集合。
Foreign key is an attribute set referencing a key in another table. 外键是引用另一张表中键的属性集合。
A join combines rows according to a specified condition. 连接根据指定条件组合行。
The result count depends on relationship cardinality and filters. 结果数量取决于关系基数和筛选器。
A foreign key constraint enforces a relationship rule; it does not automatically encrypt personal data. 外键约束强制执行关系规则;它不会自动加密个人数据。
In the lab: Design a small synthetic user-order dataset with no real personal information. 在实验环节,设计一个不包含真实个人信息的小型合成用户订单数据集。
Declare keys, test duplicate and missing-reference inserts, then check a query result against a hand-worked expected table. 声明键,测试重复插入和缺失引用插入,然后将查询结果与手工计算得出的预期表进行核对。
Known: four customers have respectively 2, 0, 3 and 1 orders. 已知:四位客户分别有 2、0、3 和 1 个订单。
An inner join of customer to order returns 2 plus 0 plus 3 plus 1 equals 6 rows. 客户到订单的内连接返回 2 加 0 加 3 加 1 等于 6 行。
A left join also retains the customer with no order as one null-matched row, giving 7 here. 左连接还会保留没有订单的客户作为一行空值匹配行,因此此处结果为 7。
Your turn: Three customers have 1, 3 and 2 orders. 轮到你了。 三位客户分别有 1、3 和 2 个订单。
How many rows does the customer-order inner join return? 客户与订单的内连接会返回多少行?
A primary key need not be a person name. 主键不必是人名。
A join is not a simple concatenation of tables. 连接操作并非简单的表拼接。
Use parameterized queries for untrusted input, rather than building SQL from raw strings. 对于不可信输入,应使用参数化查询,而非用原始字符串构建SQL语句。
Not true: A foreign key automatically encrypts every row. 不正确。 外键不会自动对每一行进行加密。
A foreign key is a referential link between tables - it enforces that the referenced row exists. 外键是表之间的引用链接,它确保被引用的行存在。
It performs no encryption; protecting row content is a separate security mechanism. 外键本身不提供加密功能。 保护行内容属于独立的安全机制。
A relational table contains rows and attributes. 关系表包含行和属性。
A join combines rows according to a specified condition. 连接操作根据指定条件组合行。
Watch for: A primary key need not be a person name. 请注意:主键不一定是人名。
Each order row carries a foreign key that points to one customer primary key. 每一行订单都带有一个外键,指向某个客户的主键。
An inner join keeps only matched pairs, so six rows. 内连接只保留能配对的行,所以是六行。
A left join keeps every customer, so Ben appears once with empty order fields: seven rows. 左连接保留所有客户,所以没有订单的 Ben 也出现一次,订单字段为空:共七行。
Customers A,B,C have 2,0,1 orders. 客户A、B和C分别有2、0和1个订单。
Compare customer-order inner and left-join row counts. 比较客户与订单的内连接和左连接的行数。
Why can counting joined rows miscount customers? 为什么统计连接后的行数会错误地计算客户数量?
Inner join returns three rows. 内连接返回 3 行。
Left join returns four rows, including a null match for B. 左连接返回 4 行,其中包括 B 的空匹配。
Count star counts rows. COUNT(*) 计算行数。
Count order id excludes nulls. COUNT(order_id) 排除空值。
Distinct customer id counts represented customers. DISTINCT customer_id 计算有代表性的客户数。
State keys and join conditions. 声明键和连接条件。
The left join retains customer 2 with null order fields. 左连接保留客户2,其订单字段为空值。
COUNT(*) includes that row, while COUNT(o.id) excludes null. COUNT星号包含该行,而COUNT括号o点id括号排除空值。
Primary keys distinguish records; customer count is not order count. 主键区分记录;客户计数不等于订单计数。
The interpolated join keyword comes from a fixed internal list, not user input. 插值的连接关键字来自固定的内部列表,而非用户输入。
Retrieve the technical meanings, then vary one input in the original transfer and justify the model condition. 请回顾相关技术术语,然后在原始迁移中改变一个输入变量,并论证模型条件的合理性。

登录或创建账户

IGCSE, A-Level & AP