内存消耗的外键优势 [英] Foreign key benefits of memory consumption

查看:100
本文介绍了内存消耗的外键优势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我创建外键的好处.让我先解释我的问题

假设我们有一个名为"SonogrpahyReport"的表,该表需要存储"patientid"和"Report"字段. 报告"字段包含实际的Word文档,其大小可能为1.2 MB左右.大多数患者报告正常,报告中有相同的单词.

如果我创建包含报表的表Master_Report_data并使用列报表在"SonogrpahyReport"和"Master_Report_data"之间创建外键,则报表数据可以存储在一个位置(仅在Master_Report_data中),并且其地址存储在(报表列)中of SonogrpahyReport).

因此,如果我有5例报告正常的患者,则数据仅消耗1.2 MB的内存.

Please tell me the benefit of creating foreign key. Let me first explain my question

Suppose we have a table called "SonogrpahyReport" which need to store "patientid", and "Report" fields. "Report" field contains actual word document which might have size of 1.2 MB or something. Most of the patients have normal report with same word in report.

If I create the table Master_Report_data which contain a report and make a foreign key between "SonogrpahyReport" and "Master_Report_data" with a column report then can report data be stored at a one place (only in Master_Report_data ) and its address store in (report column of SonogrpahyReport).

So if I have 5 patients with normal report then only 1.2 MB of memory consume by data. Is this the scenario with foreign key?

推荐答案

这就是所谓的一对多关系".对于每个报告,您可能都有许多与之相关的患者.

在SQL Server的上下文中,外键"通常是指外键约束",它指示表上一行的一个字段必须指向另一表中一行的匹配字段.

拥有外键可确保数据库的一致性(例如,使其不可能链接到无效报告的患者).
That is called a "one to many relationship". For every report, you may have many patients that it relates to.

In the context of SQL Server, a "foreign key" usually refers to a "foreign key constraint", which dictates that one field in one row on a table must point to a matching field in a row in another table.

Having foreign keys ensures database consistency (e.g., it makes it impossible to have a patient that links to an invalid report).


通常,您将使用32位整数作为外键,大小为4个字节.如果您有5位患者,那么您将使用1258311字节而不是1258291字节.

密钥几乎没有成本.

干杯.
Normally you''d use a 32 bit integer as a foreign key, which measures 4 bytes. If you had 5 patients, then you''d be using 1258311 bytes instead of 1258291 bytes.

There is virtually no cost to the key.

Cheers.


这篇关于内存消耗的外键优势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆