Application Development and Automation 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: 
Read only

primary and foreign keys

Former Member
0 Likes
10,470

wht is the use of primary key and foregin key and wht is different between them

1 ACCEPTED SOLUTION
Read only

Former Member
4,818

Praveen,

In a table, you may need some field values to be unique, that is only one entry for that particular field value .

For Ex, u want to create a table with a field 'Name' . You want only one entry for a value of 'Name' . Say only 'Praveen' . So in the table with two 'Praveen' can't exist . Here the field 'Name ' is your primary key .

Primary key can be one field or combination of multiple fields .

If it is later, the table will have one unique entry for the comination of fields .

Foreign Key : In a table, you want the values of a field present in another table .

Say u have table A, and u want to create table B, for which u want a particular field say B1 to take values from a field of table a say A1 .

it implies tht B1 can take values if the same values are there in A1 .

Here A1 is the foreign key for B1 .

Hope it helps.

~ Laxmi

  • Pls reward points for helpful answers

7 REPLIES 7
Read only

Former Member
4,818

Hi

<b>Primary Key:</b>

A primary key is a field or combination of fields that uniquely identify a record in a table, so that an individual record can be located without confusion.

<b>Foreign Key:</b>

A foreign key (sometimes called a referencing key) is a key used to link two tables together. Typically you take the primary key field from one table and insert it into the other table where it becomes a foreign key (it remains a primary key in the original table).

For eg

http://www.databasedev.co.uk/primary_foreign_key_constraints.html

Regards,

Suruchi

Read only

Former Member
4,818

Hi,

please check out the following link it might help you

http://www.sap-img.com/abap/important-abap-faq.htm

*******please reward points if the information is helpful to you***************

Read only

Former Member
4,818

Hi,

primary key defines the uniqueness of the table..

Let's take the example..MARA..the unique key or the primary key is MATERIAL number..So you cannot have two records of the same material number..the primary key is used to avoid duplicates..

By setting a foreign key brings a relation between two tables..

Let's take the example..VBAP-MATNR it has got the foreign key to the table MARA...so that you cannot enter a value which is not in the table MARA.

Check these links for more details.

http://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21ea77446011d189700000e8322d00/content.htm

Thanks

Naren

Read only

Former Member
4,819

Praveen,

In a table, you may need some field values to be unique, that is only one entry for that particular field value .

For Ex, u want to create a table with a field 'Name' . You want only one entry for a value of 'Name' . Say only 'Praveen' . So in the table with two 'Praveen' can't exist . Here the field 'Name ' is your primary key .

Primary key can be one field or combination of multiple fields .

If it is later, the table will have one unique entry for the comination of fields .

Foreign Key : In a table, you want the values of a field present in another table .

Say u have table A, and u want to create table B, for which u want a particular field say B1 to take values from a field of table a say A1 .

it implies tht B1 can take values if the same values are there in A1 .

Here A1 is the foreign key for B1 .

Hope it helps.

~ Laxmi

  • Pls reward points for helpful answers

Read only

Former Member
4,818

hi,

primary key: to maintain data consistency of a database primary is used for database tables. in sap for every database table you should have atleast one primary key and generally all primary ket fields are top most fields of a table.

foreign key: mainly used to provide referential integrities. i.e to provide relation between two tables the foreign keya are used. foreign of one table is the primary for that table and becomes foreign for another table which must have a primary key.

to have main properties of database

1. data intergrity.

2. data consistency.

3. relations b/w database tables.

these two keys are used.

if helpful reward some points.

withregards,

suresh.

Read only

Former Member
4,818

Hello Praveen,

Primary key : It is an unique key.That is, it is an unique field in the table .

Foreign key :

Check this link. It will surely help u.

<b>http://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21ea77446011d189700000e8322d00/content.htm</b>

regards,

Thasneem

Read only

Former Member
4,818

You can define a dependency between two tables that affects the tables when changes are made to rows. This relationship is called a referential constraint (or a foreign key dependency).

You can define foreign key dependencies that refer to only one primary key column in a table.

You can use the CREATE TABLE statement to define foreign keys when you create a table.

reward points if it is usefull ....

Girish