IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Example of defining foreign key


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Defining a struct PL/I & Assembler 3
No new posts defining a global LUA function in Inf... IBM Tools 1
No new posts Foreign character look different in m... COBOL Programming 3
No new posts Defining SYSLIB to USS c++ (cxx) comp... All Other Mainframe Topics 2
No new posts Defining SSL Port in TCPIP for DB2 Se... TSO/ISPF 1
Search our Forums:

Back to Top