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

tables

Former Member
0 Likes
1,022

difference between primary key and foriegn key

pls tell with eg:

pls take sflight table as example.

and tell abt the check table and foriegn key diff also

5 REPLIES 5
Read only

Former Member
0 Likes
825

Hi,

Primarykey: Primarykey is nothing but it is a key field of the table

Primary key allows each row in a table to be uniquely identified and ensures that no duplicate rows exist and no null values are entered.

Foreginkey: Foreginkey is A key used in one table to represent the value of a primary key in a related table. While primary keys must contain unique values, foreign keys may have duplicates.

Example:

SCARR is a Airline Table in this table CARRID is Primarykey/Keyfield it is main table

SFLIGHT is a Flight Table in this table CARRID is Foreginkey it is primary key is having as reference field

Cehck Table: Check Table means Actual Table of the values which is having as a primary key that field with this table you can validate the entries those values are existing or not.

Regards

Ganesh

Read only

Former Member
0 Likes
825

Hi,

Primary Key : For some applications, it is useful to uniquely identify the rows in a table by one or more columns so that you can process them in a specified sequence, for example. You can do this by assigning a “primary key.” The column names that are to create the table key are represented by the keywords PRIMARY KEY. The input values of the key columns defined in this way must not be a NULL value.

You can use the primary key to insert rows in a table in the same way as you insert rows in a base table when no primary key is defined. However, the system outputs an error message if you attempt to insert an existing value into the primary key column a second time, since the uniqueness of the column is ensured by defining the primary key.

A primary key can consist of multiple columns. However, it is unusual for a key to be constructed from more than five columns, since this makes it difficult for users to enter unique values. The arrangement of the columns behind the keywords PRIMARY KEY defines the key sequence.

Foreign Key : You can define the relationships between tables in the ABAP Dictionary by creating foreign keys.Using foreign keys, you can easily create value checks for input fields.A foreign key links two tables T1 and T2 by assigning fields of table T1 to the primary key fields of table T2.Table T1 is called the foreign key table (dependent table) and table T2 the check table (referenced table). The pair of fields for the two tables must have the same data type and length. One field of the foreign key table therefore corresponds to each key field of the check table. This field is called the foreign key field.

A foreign key permits you to assign data records in the foreign key table and check table. One record of the foreign key table uniquely identifies one record of the check table using the entries in the foreign key fields.

Check Table and Foreign Key Diff :

When, one of the foreign key fields is marked as the check field, this means that the foreign key relationship is maintained for this field.

When an entry is made in the check field, there is a check whether the check table contains a record with the key defined by the values in the foreign key fields. If this is so, the entry is valid. Otherwise the system rejects the entry.

Hope this helps.

Please reward if useful.

Thanks,

Srinivasa

Read only

Former Member
0 Likes
825

Primary key is used to find the unique row.

The field which is a primary key in one table will act as a foreign key in another table if the same field is there.

If value table is provided for any domain then the table given in value table will become the check table.

Read only

Former Member
0 Likes
825

When a primary key is made then it is a parent table or master table ,when a foreign key in assigned to that table then the table where foreign key is made is said to be child table or transaction table .

Primary key : To Fetch and identify a record uniquely.

Foreign key : To create relationship between tables.

Ex: SFlight is master table(Flight Specification details),some fields are :

Flightno is the primary key,where flightsize,capacity,enginepower,maximumspeedlimit

are the other fields in this table .

Tflight is the transaction table( Flight timeing details ) ,

Flightno is foreign key .where Arrival time,departure time ,boarding place ,destination ,etc

are the other fields in this child table.

Check table is a table which has a primary key ,When U give the relationship between two tables

for ex: in transaction table when u select a row and assign it as foreign key and click on foreign key symbol ,then it will ask for check table name ,enter the parent table name .

Check table is mainly used to validate the entries in the transaction table.

Read only

Former Member
0 Likes
825

Primary key is used to uniquely identify a record in the table.It will not be duplicated.

Primary key when used in the other table for reference can set to be Foriegn key.Foriegn key can be dupliated.

Check table we used here to make the values (Primary key values) from Parent table whether we entering the values which was presented in the Parenttable.In child table it will be foriegn key and it will be checked when we make the checkbox true while creating the foriegn key.

SCARR is a parent table and here CARRID is primarykey.

SFLIGHT is a Flight child Table in this table CARRID is Foreginkey.This want to contain the only values which r presented in parent table..

Now we cant delete the parent table primary field since it has a reference in another table.First we want to delete in child table and then in parent table...