Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Example of defining foreign key

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
ysuryawanshi_mcs
Warnings : 1

New User


Joined: 25 Mar 2006
Posts: 15
Location: pune(India)

PostPosted: Mon Apr 03, 2006 4:33 pm    Post subject: Example of defining foreign key
Reply with quote

could anybody givi me example of defining foreign key
suppose i hav 2 tables 1.employee 2. dept
emp(eno,ename)
dept(dno,dname)

now i want dno as foreign key in emp so how should i write this
Back to top
View user's profile Send private message

appasi

New User


Joined: 12 Dec 2005
Posts: 20
Location: Bangalore

PostPosted: Mon Apr 03, 2006 4:56 pm    Post subject:
Reply with quote

Hi ysuryawanshi_mcs,

If you want dno as foreign key then dno colomn must be in emp table as primary key colomn ( not the same colomn but same type and length should be same).

Please correct me if i am wrong

Appasi
Back to top
View user's profile Send private message
Mr.Niceguy

New User


Joined: 16 Jun 2005
Posts: 63

PostPosted: Mon Apr 03, 2006 5:49 pm    Post subject:
Reply with quote

Hi,

Create one more field (DNO) in emp table having same data type and length. Assign DNO(dept) as primary key and DNO(emp) as foreign key.
Back to top
View user's profile Send private message
perez_a

New User


Joined: 02 Feb 2006
Posts: 25
Location: Italy

PostPosted: Wed Apr 05, 2006 5:57 pm    Post subject: Re: Example of defining foreign key
Reply with quote

HI ysuryawanshi_mcs,

CREATE TABLE DEPT (
DNO <SAME TYPE OF ENO>,
DNAME ,
CONSTRAINT
FK01 FOREIGN KEY (DNO)
REFERENCES EMP(ENO)
);

AND REMEMBER THAT ENO MUST BE PRIMARY KEY IN EMP.
HAVE A NICE DAY.
Back to top
View user's profile Send private message
friend_prasad

New User


Joined: 06 Jan 2006
Posts: 12

PostPosted: Mon Apr 10, 2006 10:29 am    Post subject: Re: Example of defining foreign key
Reply with quote

hi yogesh suryawanshi this is prasad kulkarni

how r u ?
what is going on ?
have u completed u r syllabus
the answer of u r query is that which is given by the last guy
some body perez try it .if u havenot understand then mail me on my mail id

thanks
prasad
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Defining a VSAM File as CICS Table sainathm CICS 2 Mon Mar 03, 2014 12:03 pm
No new posts Enforcing Foreign Key gylbharat DB2 10 Wed Apr 17, 2013 9:39 pm
No new posts Unable to create a foreign key princegaurav DB2 2 Tue Nov 06, 2012 6:24 pm
No new posts defining an alias (alternate entrynam... PUMA All Other Mainframe Topics 1 Thu Feb 23, 2012 4:57 pm
No new posts Primery Key / foreign key between Views bauer DB2 1 Fri Dec 16, 2011 11:56 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us