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 Key Foreign Key Problem

Former Member
0 Likes
766

I have created three tables as per following,


1) Department

fields: dep_id(primary key),

          dep_name

2)Faculty Table

fields: fac_id(primary key),

          fac_name,

          dep_id(foreign key)

3)Student Table

fields: std_id(primary key),

          std_name,

          std_add,

          fac_id(foreign key),

          dep_id(foreign key).

Now i want to make condition that fac_id and dep_id should be correspond in student table ,

for example ,

if i enter 1 as fac_id then it should automatically fetch it's dep_id from the fac_id..

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
713

Hello,

As per my understanding there is no need to dep_id in student table , b'cz based on Student id you can get a Unique fac_id and Based on fac_id u can get unique Dept_id and Name, so remove

dep_id from student table.

BR

Chandra..

5 REPLIES 5
Read only

former_member209120
Active Contributor
0 Likes
713

Hi Alex Hanes

See this link to create foreign key for table

http://www.saphub.com/abap-tutorial/how-to-create-a-foreign-key-in-sap-table/

Read only

0 Likes
713

Thanks on your prompt reply to this.I am able to make it work with 2 tables.But, when i try it on 3 tables things get messy. It looses it's consistency.

Read only

FredericGirod
Active Contributor
0 Likes
713

Hi Alex,

I'm not sure you could do this (easily) with SAP. Maybe if you build a logical database (with some Abap code). But SAP didn't use the "advanced tools" of Oracle because it could used several different database.

regards

Fred

Read only

Former Member
0 Likes
714

Hello,

As per my understanding there is no need to dep_id in student table , b'cz based on Student id you can get a Unique fac_id and Based on fac_id u can get unique Dept_id and Name, so remove

dep_id from student table.

BR

Chandra..

Read only

0 Likes
713

yeah that's right thanks dear.