Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Updated 1-Nov-10 2:59am
v2

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).
 
Share this answer
 
Comments
RDBurmon 2-Nov-10 2:43am    
ya this is on the part of data constraint but i am asking is there any such purpose of key so that it eat less space in memroy.

that why here i put the Q like :

"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? "
AspDotNetDev 2-Nov-10 17:42pm    
You can save memory by storing a large amount of data once and referring to it with a small amount of data several times (rather than storing that large amount of data multiple times), obviously. Creating a foreign key constraint should have no effect on memory.
RDBurmon 6-Nov-10 5:21am    
Thanks Frnds.
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.
 
Share this answer
 
Comments
RDBurmon 2-Nov-10 2:44am    
thks for the ans but my Q is

"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? "

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900