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: 

keys

Former Member
0 Kudos

hi,

what are the primary key,foreign key and generic key?

Thanks in advance.....

3 REPLIES 3

Former Member
0 Kudos

hi,

Primary key is the UNIQUE key in each and every table.

There won't be duplicates and NULL values for this.

Foreign key means it is a key in one table and a Primary key in other table.

In the first table you have to define the relationship with that second table.

Primary key : The field which is Unique and not null is called the Primary Key field

Foreign Key : To establish the relations between 2 tables the same key kield in another table is the Foreign key.

Foreign key can or can not be Unique and not-null.

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

Message was edited by:

Roja Velagapudi

Former Member

Former Member
0 Kudos

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.

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

regards,

srinivas

<b>*reward for useful answers*</b>