Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Foreign key

Former Member
0 Kudos

Hi Gurus,

I have a little bit query related to foreign key. Please anybody clariffy me.

How can I make a field which is not a primary key as a foreign key is that possible?

Thanks in adance and waiting for replies...

Regards,

Ravi.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

Foreign key

A foreign key creates a link between two tables T1 and T2. Every primary key field from T1 (check table) is assigned a field from table T2 (foreign key field). The fields from T2 assigned to primary key fields are marked as foreign key fields.

The most important function of the foreign key is the support of data integrity. The foreign key fields can only accept values which appear in the primary key of the check table. During input the values of the foreign key fields can thus be checked against the entries of the assigned key fields of the check table.

Foreign keys are also the foundation for defining lock objects, maintenance views and help views. These objects contain fields from several tables. All the tables used in such an object must be linked with foreign keys.

Reward points if useful

Regards

Anji

6 REPLIES 6

Former Member
0 Kudos

Hi

Foreign key

A foreign key creates a link between two tables T1 and T2. Every primary key field from T1 (check table) is assigned a field from table T2 (foreign key field). The fields from T2 assigned to primary key fields are marked as foreign key fields.

The most important function of the foreign key is the support of data integrity. The foreign key fields can only accept values which appear in the primary key of the check table. During input the values of the foreign key fields can thus be checked against the entries of the assigned key fields of the check table.

Foreign keys are also the foundation for defining lock objects, maintenance views and help views. These objects contain fields from several tables. All the tables used in such an object must be linked with foreign keys.

Reward points if useful

Regards

Anji

0 Kudos

Hi Anji,

Very thinks for the immediate response with detailed analysis of foriegn key. Could you please suggest me for my question.

How can I make a field which is not a primary key as a foreign key is that possible?

Regards,

Ravi..

0 Kudos

Hello Ravi,

<i>How can I make a field which is not a primary key as a foreign key is that possible? </i>

The answer is not possible.

The check table must have a key field which has the same domain as the check field of the foreign key table.

The table u selected cannot be used as a check table because it does not have a key field with the same domain as the check field.

The solution is :Select a table as check table which satisfies the above condition. The possible candidates can be displayed via the F4 help for the input field 'check table' in the foreign key maintenance.

Regards,

Deepu.k

0 Kudos

Hi Deepu,

Thankq very much for the solution. Thanks to all for giving valuable suggestions.

Regards,

Ravi.

raymond_giuseppi
Active Contributor
0 Kudos

Look at <a href="http://help.sap.com/saphelp_47x200/helpdata/EN/images/locate.gif">Type of Foreign Key Fields</a>

The Type of foreign key fields describes what the foreign key fields in the foreign key table mean.

The following types of foreign key field can be defined:

  • No key fields/candidates: The foreign key fields are <b>neither primary key fields</b> of the foreign key table nor do they uniquely identify a record of the foreign key table (key candidates). For this reason, the foreign key fields do not (partially) identify the foreign key table.

  • Key fields/candidates: The foreign key fields are either primary key fields of the foreign key table or they already uniquely identify a record of the foreign key table (key candidates). The foreign key fields therefore (partially) identify the foreign key table.

  • Key fields of a text table: The foreign key table is a

text table for the check table, that is the key of the foreign key table only differs from the key of the check table in that it has an additional language key field. This is a special case of the type Key fields/candidates.

Regards

Former Member
0 Kudos

Hello,

All the tables that can be included in a lock object must be linked with foreign keys. There are a number of restrictions to the valid relationships.

The foreign key relationships of the tables of the lock object must form a tree. The tables are the nodes of the tree. The links of the tree mean is the check table of.

The foreign key fields must be key fields of the foreign key table.

The foreign key relationships defined between the base tables of the lock objects may not have any field that is checked against more than one other field. A field therefore may not occur twice as foreign key field in a relationship and may not be checked against two different fields in two different foreign key relationships.

You must keep one restriction in mind for multi-structured foreign keys. If a field is assigned to a field that is outside the check table, the table containing this field must be in a sub-tree that contains the check table of this foreign key relationship as a root.

These conditions are always satisfied if the key of the foreign key table is an extension of the key of the check table.

Conditions 2, 3 and 4 are meaningless if the particular foreign key field was excluded from the assignment to the key fields of the check table by marking it as generic or setting it to a constant. This is also true for multi-structured foreign keys if the foreign key field refers to a table that is not contained in the lock object.

Regards,

Deepu.k