View previous topic :: View next topic
|
Author |
Message |
ysuryawanshi_mcs Warnings : 1 New User
Joined: 25 Mar 2006 Posts: 15 Location: pune(India)
|
|
|
|
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 |
|
|
appasi
New User
Joined: 12 Dec 2005 Posts: 20 Location: Bangalore
|
|
|
|
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 |
|
|
Mr.Niceguy
New User
Joined: 16 Jun 2005 Posts: 63
|
|
|
|
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 |
|
|
perez_a
New User
Joined: 02 Feb 2006 Posts: 25 Location: Italy
|
|
|
|
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 |
|
|
friend_prasad
New User
Joined: 06 Jan 2006 Posts: 12
|
|
|
|
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 |
|
|
|