|
Explain the concept of foreign key. By: Praba Karan Foreign key is nothing but simply we can say, "a field in one table related to field in another table". See the below example:- Consider, there are two tables like emp_personal and emp_official. In emp_personal table , the fields are empid, empname, dob for example. In this table, empid is the primary key field. In emp_official table, the fields are empid, dept, designation for example. In this also, empid is the Primary key or may not be a Primary key field. Now we relate these two tables using the foreign key relationship. Foreign key relationship is used to avoid the redundancy mainly. Now, emp_personal is the Check table (Because it holds the empid field, which has the primary key...) emp_official table is the Foreign key table (Because it holds the empid field, which may or may not be a Primary key). Now, the foreign key relationship is given. (click the KEY Like icon in ABAP Dict - Database Table : Emp Official ) Tables are ready to enter the records...for example create some 5 records in the emp_personal table . Table : emp_personal : Primary Key - empid empid empname
empdob
Status
Records are saved in the table : emp_personal. Now, we are tryiing to create records in emp_official table. Table : emp_official : Primary Key or not a Primary Key - empid empid dept
designation Status
Now, if you try to create the record which is not in the table emp_personal,
which has the empid = 6. But it'll not allow us to create the record 6,
because of the foreign key relationship between these two tables....
Now, the foreign key relationship helps us to avoid the duplicate entry.
This is the concept of Foreign key.
Get help for your ABAP problems
ABAP Books
More ABAP Tips
SAP Basis, ABAP Programming and Other IMG Stuff http://www.sap-img.com All the site contents are Copyright © www.sap-img.com
and the content authors. All rights reserved.
|