function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Adam VenerAdam Vener 

What are Primary and Foreign keys?

Hello,

I'm new to the Community and the SF Community cloud. I am currently taking the Admin Beginner courses, and there are times when I come across terms in the text that are not self-explanatory.

As example, in the Understanding Custom and Standard Objects module, the text says, under "Overview of Objects":

"Each table comprises a number of columns of a particular data type, such as text, number, or date. Information is stored in rows of the table. Tables can be related to other tables, using primary and foreign keys. Apps manage information by creating, reading, updating, and deleting rows in a table"

The problem is, I am not a database programmer, and I have no idea what primary and foreign keys are. They are not described in this document.
Is it relevant to what I am learning and if so, can someone please provide a description of these terms as they relate to the paragraph above?

Thank you for any feedback!

 
Best Answer chosen by Adam Vener
ajay rawat 14ajay rawat 14
Hi Adam
            Primary key and Foreign key are relational database concepts. It is use to relate one table information to another for example I want to store employes and company details in my database so If I create a table and create column like emp name, emp contact,  Company Name, Company address then there is data duplication I have to enter same value for Company Name and Company address. If company address is changed then I have to update all records field. This is not a proper database structure and it will have data duplication.

To avoid this there is a concept of Primary and Foreign key in this I will create a separate table for company details and emp details.My company details will have a unique key Like Company Id which enforces the entity integrity of the table and will help me to connect with other records in different table. My another table Emp Detail will have a column which column called Company Id which is used to connect to table reords . In master details relationship master table Id field is Primary key and master detail field in detal table is Foreign key.
You can find more on
https://developer.salesforce.com/docs/atlas.en-us.fundamentals.meta/fundamentals/adg_database_concepts_relational.htm

Thanks and Regards,
Ajay RAwat


 

All Answers

ajay rawat 14ajay rawat 14
Hi Adam
            Primary key and Foreign key are relational database concepts. It is use to relate one table information to another for example I want to store employes and company details in my database so If I create a table and create column like emp name, emp contact,  Company Name, Company address then there is data duplication I have to enter same value for Company Name and Company address. If company address is changed then I have to update all records field. This is not a proper database structure and it will have data duplication.

To avoid this there is a concept of Primary and Foreign key in this I will create a separate table for company details and emp details.My company details will have a unique key Like Company Id which enforces the entity integrity of the table and will help me to connect with other records in different table. My another table Emp Detail will have a column which column called Company Id which is used to connect to table reords . In master details relationship master table Id field is Primary key and master detail field in detal table is Foreign key.
You can find more on
https://developer.salesforce.com/docs/atlas.en-us.fundamentals.meta/fundamentals/adg_database_concepts_relational.htm

Thanks and Regards,
Ajay RAwat


 
This was selected as the best answer
Amit Chaudhary 8Amit Chaudhary 8
In smiple word
Evey object have ID field that is primary key
If you will create lookup or master detail detail relation ship on child object that will be Foreign key

Let us know if this will help you
Adam VenerAdam Vener
Both of your replies were quick, very helpful, and explanatory.

Thank you very much!